简体   繁体   English

Azure AD是否提供API方法来以编程方式验证用户?

[英]Does Azure AD provide an API method to validate a user programmatically?

I want to validate Azure AD users through both a web app and a native mobile app, though Azure AD isn't the only IdP that I'm using. 我想通过Web应用程序和本机移动应用程序验证Azure AD用户,尽管Azure AD不是我正在使用的唯一IdP。

I've read the OAuth2 article but I'm having trouble tracking down an API method to validate against a user. 我已经阅读了OAuth2文章,但是在跟踪API方法以针对用户进行验证时遇到了麻烦。 One answer notes you can pass username and password parameters when you fetch the token, but it doesn't seem to validate against that. 一个答案指出,您在获取令牌时可以传递usernamepassword参数,但似乎无法对此进行验证。

There's an example of DotNet solution but I'm not familiar with .NET - tried running it and ran into a System.TypeLoad Exception ( Could not load type of field 'Microsoft.Owin.Security.ActiveDirectory.WsFedMetadataRetriever:CS$<>9__CachedAnonymousMethodDelegate5' ) 有一个DotNet解决方案的示例,但我对.NET不熟悉-尝试运行它并遇到了System.TypeLoad异常( Could not load type of field 'Microsoft.Owin.Security.ActiveDirectory.WsFedMetadataRetriever:CS$<>9__CachedAnonymousMethodDelegate5'

I've previously tried to setup a SimpleSAML solution but the downside is that for native apps it requires extra work and may not be suitable. 我以前曾尝试设置SimpleSAML解决方案,但缺点是,对于本机应用程序,它需要额外的工作,可能不适合。

I recommend you redirect the users to the Azure AD login page. 我建议您将用户重定向到Azure AD登录页面。

You technically can try to validate the user by using the Resource Owner Password Credentials grant. 从技术上讲,您可以尝试使用“资源所有者密码凭据”授予来验证用户。 But it will not work always. 但是,它不会总是工作。

This involves you making a POST request to the OAuth token endpoint with form data similar to this: 这涉及您使用类似于以下内容的表单数据向OAuth令牌端点发出POST请求:

grant_type=password&username=user@example.com&password=Password&client_id=your-client-id&client_secret=your-client-secret&resource=resource-you-want-the-token-for

The resource could be https://graph.windows.net since you have access to that by default. 该资源可能是https://graph.windows.net因为默认情况下您可以访问该资源。 If the result is successful, then yes, the user exists and the credentials are valid. 如果结果成功,则是,该用户存在并且凭据有效。

But if it fails, it can happen because: 但是,如果失败,则可能由于以下原因而发生:

  • The user does not exist 用户不存在
  • The password is wrong 密码错误
  • The user has multi-factor authentication turned on 用户已启用多因素身份验证
  • The user is a federated user (from on-prem AD), and authentication must be done via ADFS 该用户是联盟用户(来自本地AD),并且必须通过ADFS进行身份验证

So it just simply cannot work in some cases. 因此,在某些情况下它根本无法工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM