Azure AD B2C登录后,xamarin ios应用程序未返回

时间:2018-03-29 19:41:21

标签: azure xamarin xamarin.forms azure-active-directory azure-ad-b2c

我在我的B2C租户中添加了一个Native应用程序。

App.xaml.cs代码如下所示

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

条目
<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>

只需点击一下按钮,我就有了这段代码

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登录页面。成功登录后,它就会停留在那里。如果我按“完成”然后它会返回到应用程序,但用户取消了验证。成功登录后不应该回到应用程序吗?

1 个答案:

答案 0 :(得分:0)

iOS特定注意事项

在AppDelegate.cs中,

UserDetailsClient.iOS只需要一行额外的行。您需要确保OpenUrl处理程序在下面的代码段中显示为:

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

再一次,这个逻辑旨在确保一旦认证流程的交互部分结束,流程就会回到MSAL。