使用 Android 本机应用程序中的 ADAL 库在 Azure AD 上对用户进行身份验证 [英] Authenticate the user on Azure AD using ADAL library from Android native app

查看:19
本文介绍了使用 Android 本机应用程序中的 ADAL 库在 Azure AD 上对用户进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个要求,用户应该从本机应用程序(Android、iOS)登录,而不从应用程序调用 Microsoft 登录 Web 视图窗口.我们有示例代码演示使用用户名和 Azure AD 的非交互式身份验证.来自 .net 控制台应用程序的密码.

We have a requirement where users should signin from Native apps(Android, iOS) without invoking Microsoft login web view window from the app. We have the sample code that demonstrates non-interactive authentication to Azure AD using a username & password from the .net console application.

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

示例代码:

AuthenticationResult 结果 = null;

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 中实现.

The same way we are trying to achieve it in Android. First I would like to know whether it is possible to do the same in Android and if yes, can you please provide me some sample code so we can implement in Android.

推荐答案

首先,答案是肯定的.Java中也有相同的示例代码 https://github.com/Azure-Samples/active-directory-java-native-headless.您需要遵循 Java 示例代码并使用 adal4android,这里是 这里.

First, the answer is yes. And there is a same sample code in Java https://github.com/Azure-Samples/active-directory-java-native-headless. You need to follow the Java sample code and rewrite it using adal4android, which maven repository is here.

希望对你有帮助.

这篇关于使用 Android 本机应用程序中的 ADAL 库在 Azure AD 上对用户进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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