【问题标题】:Passing user credentials to Adal AquireTokenAsync将用户凭据传递给 Adal AquireTokenAsync
【发布时间】:2017-06-25 23:02:37
【问题描述】:

我正在使用 Adal(Active Directory 身份验证库)版本 3.13.x。我正在做类似下面的事情来获取访问令牌

AuthResult = await AuthContext.AcquireTokenAsync(relyingUrl, ServiceConstants.CLIENTID, ServiceConstants.RETURNURI, param);

我也需要传递 UserCredentials,但现在我只能将一个参数传递给 UserCredential(),这与 Adal 的 2.x.x 版本不同。

我也尝试按照this 解决方案中的建议使用UserPasswordCredential,但由于我想从移动应用程序中获取令牌,我只能访问.net Core,因此无法使用UserPasswordCredential

我想在获取令牌时同时传递用户名和密码。有什么办法可以实现吗?

任何帮助将不胜感激。

编辑

在尝试了 Fei Xue - MSFT 的解决方案后,我收到以下 503 错误。

【问题讨论】:

    标签: mobile active-directory passwords credentials adal


    【解决方案1】:

    我想在获取令牌时同时传递用户名和密码。有什么办法可以实现吗?

    在这种情况下,我们可以直接执行 REST 请求,而不是使用客户端库。这是一个示例供您参考:

    Post:https://login.microsoftonline.com/{tenant}/oauth2/token
    
    resource={resource}&client_id={clientId}&grant_type=password&username={userName}&password={password}
    

    更新

    string authority = "https://login.microsoftonline.com/{tenantid}";
    string resrouce = "https://graph.windows.net";
    
    string clientId = "";
    string userName = "";
    string password = "";
    UserPasswordCredential userPasswordCredential = new UserPasswordCredential(userName, password);
    AuthenticationContext authContext = new AuthenticationContext(authority);
    var token = authContext.AcquireTokenAsync(resrouce, clientId, userPasswordCredential).Result.AccessToken;
    
    Console.WriteLine(token);
    

    【讨论】:

    • 感谢您的回复。知道如何使用 AD FS 的权限来做到这一点吗?
    • 不熟悉 AD FS,但是您可以尝试使用库通过此流程获取令牌并通过 Fiddler 捕获请求以获取详细信息。
    • 请检查我的编辑。我对此很陌生,因此出现了这些问题。
    • 使用Adal库发送请求是否成功?
    • 我还没有尝试将这种方法与 adal 一起使用。你能告诉我怎么做吗?
    猜你喜欢
    • 1970-01-01
    • 2018-07-15
    • 1970-01-01
    • 2016-03-12
    • 1970-01-01
    • 1970-01-01
    • 2018-04-08
    • 2018-03-09
    • 1970-01-01
    相关资源
    最近更新 更多