使用Android本机应用程序中的ADAL库在Azure AD上对用户进行身份验证

时间:2017-04-04 13:46:44

标签: android azure azure-active-directory adal azure-android-sdk

我们要求用户在不从应用程序调用Microsoft登录Web视图窗口的情况下从Native应用程序(Android,iOS)登录。我们有一个示例代码,演示了使用用户名和放大器对Azure AD进行非交互式身份验证。来自.net控制台应用程序的密码。

https://github.com/Azure-Samples/active-directory-dotnet-native-headless

示例代码:

AuthenticationResult result = null;

        authContext = new AuthenticationContext(authority, new FileCache());

        string userName = "user@sample.onmicrosoft.com";
        string password = "Test@123";

        UserCredential uc = new UserPasswordCredential(userName, password);

        result = authContext.AcquireTokenAsync(appResourceId, clientId, uc).Result;

我们尝试在Android中实现它的方式相同。首先,我想知道是否可以在Android中执行相同操作,如果是,您能否请我提供一些示例代码,以便我们可以在Android中实现。

1 个答案:

答案 0 :(得分:3)

首先,答案是肯定的。 Java [{3}}中有相同的示例代码。您需要遵循Java示例代码并使用https://github.com/Azure-Samples/active-directory-java-native-headless重写它,maven存储库为adal4android

希望它有所帮助。