gpt4 book ai didi

azure - 在 Xamarin Forms 中更改 Azure AD B2C 密码的方法

转载 作者:行者123 更新时间:2023-12-03 05:52:20 25 4
gpt4 key购买 nike

我很难在 Xamarin 表单中更改密码方法。我尝试使用:

https://graph.windows.net/me/changePassword?api-version=1.6

很难找到使其在 Xamarin 表单中工作的引用,这就是我到目前为止所拥有的。

这是我的模型:

using Newtonsoft.Json;

namespace KGVC.Models
{
public class GraphModel
{
const string ChangePassword = "https://graph.windows.net/me/changePassword?api-version=1.6";
[JsonProperty("currentPassword")]
public static string currentPassword { get; set; }

[JsonProperty("newPassword")]
public static string newPassword { get; set; }


}
}

...这是我更改密码的用户界面:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="KGVC.Views.LogoutPage">
<StackLayout HorizontalOptions="Center" VerticalOptions="Center">
<Button x:Name="logoutButton" Text="Logout" Clicked="OnLogoutButtonClicked" />
<Label x:Name="messageLabel" FontSize="Medium" />
<Label Text="Change Password" FontSize="Large" HorizontalOptions="Center" Margin="5"/>
<Label Text="Current Password" VerticalOptions="Center" Margin="5"/>
<Entry x:Name="currentPassword"/>
<Label Text="New Password" VerticalOptions="Center"/>
<Entry x:Name="newPassword"/>
<Button Text="Change Password" Clicked="ChangePasswordClicked" Margin="20"/>
</StackLayout>
</ContentPage>

...这是迄今为止我的方法:

using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using KGVC.Models;
using Microsoft.Identity.Client;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace KGVC.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class LogoutPage : ContentPage
{

AuthenticationResult authenticationResult;

public LogoutPage(AuthenticationResult result)
{
InitializeComponent();
authenticationResult = result;
}

protected override void OnAppearing()
{
if (authenticationResult != null)
{
if (authenticationResult.User.Name != "unknown")
{
messageLabel.Text = string.Format("Welcome {0}", authenticationResult.User.Name);
}
else
{
messageLabel.Text = string.Format("UserId: {0}", authenticationResult.User.UniqueId);
}
}

base.OnAppearing();
}
public void ChangePasswordClicked(object sender, EventArgs e)
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post,
"https://graph.windows.net/me/changePassword?api-version=1.6");
// request.Headers.Authorization =
// new AuthenticationHeaderValue("Bearer", authResult.AccessToken);
//var response = await client.SendAsync(request);
//var content = await response.Content.ReadAsStringAsync();
}

async void OnLogoutButtonClicked(object sender, EventArgs e)
{
App.AuthenticationClient.UserTokenCache.Clear(Constants.ApplicationID);
await Navigation.PopAsync();
}


}
}

结果是来 self 的登录 View 模型的参数,这是我的 App.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KGVC.Models;
using KGVC.Views;
using Microsoft.Identity.Client;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Unity;
using Xamarin.Forms;

namespace KGVC
{
public partial class App : Application
{

public static PublicClientApplication AuthenticationClient { get; private set; }
public App()
{
InitializeComponent();
UnityContainer unityContainer = new UnityContainer();
// unityContainer.RegisterType<LoginService>();
ServiceLocator.SetLocatorProvider(() => new UnityServiceLocator(unityContainer));
AuthenticationClient = new PublicClientApplication(Constants.ApplicationID);
MainPage = new NavigationPage(new LoginPage());
}

protected override void OnStart()
{
// Handle when your app starts
}

protected override void OnSleep()
{
// Handle when your app sleeps
}

protected override void OnResume()
{
// Handle when your app resumes
}
}
}

是否有任何我可以查找的引用资料或 GitHub 文件来解决我的问题,以及我应该在我的方法中添加什么内容还是我需要其他内容?

最佳答案

嘿,看起来您试图直接在图形 API 上更改密码,我认为这是不允许的,通过 B2C 使用重置密码策略,它将为您处理所有事情

关于azure - 在 Xamarin Forms 中更改 Azure AD B2C 密码的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46321036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com