Active Directory:MSAL(UWP)PublicClientApplication.AcquireTokenAsync(...)返回异常

时间:2018-04-27 09:39:49

标签: c# azure-active-directory msal xamarin.uwp

我正在尝试使用Active Directory实现登录/登录功能。我基于这个b2c-xamarin sample

以下是我遇到问题的相关代码。我在这里进行了修改以简化可读性。我已为任何noteworty插入注释,尤其是AcquireTokenAsync:

string ClientID     = "<application_id_of_b2c_application>"
string Authority    = "https://login.microsoftonline.com/tfp/<b2c_tenant_name>/<signin_policy_name>/oauth2/v2.0/authorize"

PublicClientApplication PCA = new PublicClientApplication(ClientID, Authority);

//  The application says to override this which I do not as I am not sure if its required for actual sign in
PCA.RedirectUri = $"msal{ClientID}://auth";

//  UWP SIGN IN CODE
string Scopes = { "User.Read" };
string PolicySignUpSignIn = "<signin_policy_name>";

//  Arguments #2 and #3 both return null.  This happens also with the unmodified sample that works.
//  I do not know what to put in for argument #1 (scopes) - I have tried numerous combinations to no avail.  currently I have { "User.Read" }
AuthenticationResult ar = await PCA.AcquireTokenAsync(Scopes, GetUserByPolicy(PCA.Users, PolicySignUpSignIn), PCA.UiParent);

调用AcquireTokenAsync时获得的重复是以下内容(为了便于阅读而截断 - 我插入了开头和结尾)

  

{Microsoft.Identity.Client.MsalException:WAB身份验证失败   ---&GT; System.IO.FileNotFoundException:指定的协议未知。 (来自HRESULT的异常:0x800C000D)at   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)......(TRUNCATION)......   ---从抛出异常的先前位置开始的堆栈跟踪结束--- at   UserDetailsClient.MainPage.d__2.MoveNext()     ErrorCode:authentication_ui_failed}

我认为问题的方法可能是以下任何一种:

  1. 使用不正确的参数(客户端ID /权限)
  2. 初始化PublicClientApplication(PCA)
  3. 我对AcquireTokenAsync使用了错误的Scopes参数 - 目前是:{&#34; User.Read&#34; }
  4. 我需要在UWP中调用AcquireTokenAsync之前指定正确的重定向URI并将其分配给PCA
  5. 我在Azure端错过了一些东西
  6. 我已根据Azure AD中的值尝试了许多参数组合,但无济于事。我真的可以使用一些帮助。

0 个答案:

没有答案