Azure AD B2C登录后xamarin ios应用未返回 [英] xamarin ios app is not returning after Azure AD B2C login

查看:135
本文介绍了Azure AD B2C登录后xamarin ios应用未返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在B2C租户中添加了本机应用程序.

I added a Native app in my B2C Tenant.

App.xaml.cs代码看起来像这样

App.xaml.cs code looks like this

public static PublicClientApplication PCA = null;

// Azure AD B2C Coordinates
public static string Tenant = "something.onmicrosoft.com";
public static string ClientID = "*********-0e3a-483a-9e15-7896c524ed1d";
public static string PolicySignUpSignIn = "B2C_1_EmailSignup";
public static string PolicyEditProfile = "B2C_1_PasswordReset";
public static string PolicyResetPassword = "B2C_1_PasswordReset";

public static string[] Scopes = { "https://havethat.onmicrosoft.com/demoapi/demo.read" };
public static string ApiEndpoint = "https://havethat.azurewebsites.net/hello";

public static string AuthorityBase = $"https://login.microsoftonline.com/tfp/{Tenant}/";
public static string Authority = $"{AuthorityBase}{PolicySignUpSignIn}";
public static string AuthorityEditProfile = $"{AuthorityBase}{PolicyEditProfile}";
public static string AuthorityPasswordReset = $"{AuthorityBase}{PolicyResetPassword}";

public static UIParent UiParent = null;

public App()
{
    // default redirectURI; each platform specific project will have to override it with its own
    PCA = new PublicClientApplication(ClientID, Authority);
    PCA.RedirectUri = $"msal{ClientID}://auth";

    MainPage = new NavigationPage(new MainPage());
}

info.plist文件的App ID具有以下条目

info.plist file has the following entry for App ID

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string>URL Type 1</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>msal********-0e3a-483a-9e15-7896c524ed1d</string>
        </array>
    </dict>
</array>

只需单击一个按钮,我便有了此代码

on a simple click of a button i have just this code

async void OnSign(object sender, EventArgs e)
{
    try
    {
        AuthenticationResult ar = await App.PCA.AcquireTokenAsync(App.Scopes, GetUserByPolicy(App.PCA.Users, App.PolicySignUpSignIn), App.UiParent);
        UpdateUserInfo(ar);
    }
    catch (Exception ex)
    {

    }
}

现在此代码将我带到B2C登录页面.成功登录后,它将停留在该位置.如果我按完成",则它会返回到应用程序,但用户会取消身份验证.成功登录后不应该回到应用程序吗?

now this code takes me to B2C Login page. after successful login it just stays there. If i press "Done" then it goes back to the app with exception that user cancels authenitcation. Shouldn't it just come back to the app after successful login ?

推荐答案

iOS特定注意事项

UserDetailsClient.iOS在AppDelegate.cs中仅需要多一行.您需要确保OpenUrl处理程序的外观与下面的代码段相同:

iOS specific considerations

UserDetailsClient.iOS only requires one extra line, in AppDelegate.cs. You need to ensure that the OpenUrl handler looks as in snippet below:

csharp public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options) { 
    AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(url, ""); 
    return true; 
} 

再次,此逻辑旨在确保一旦完成身份验证流的交互部分,该流将返回到MSAL.

Once again, this logic is meant to ensure that once the interactive portion of the authentication flow is concluded, the flow goes back to MSAL.

这篇关于Azure AD B2C登录后xamarin ios应用未返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆