无头身份验证Azure AD B2C

编程入门 行业动态 更新时间:2024-10-24 18:25:15
本文介绍了无头身份验证Azure AD B2C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在为Azure AD B2C寻找一种通过用户名/密码以无头方式对用户进行身份验证的方法。Azure AD B2C很棒,但我们觉得登录的重定向可能会导致客户困惑(有时甚至会被一些浏览器阻止)。我们还希望完全控制客户的用户体验。

我研究了Adal和Graph API,但尚未找到任何东西。

吉娜

推荐答案

如here所述,您可以为Client Credential Flow服务帐户使用Azure AD App。它不是最优的,但它是有效的。

  • Define an Azure AD App用于Web API
  • Define an Azure AD App每个服务帐户
  • 配置Web API以接受来自B2C租户和Azure AD的令牌
    • 假设您已经为B2C配置了Web API...
    • Azure AD App的已知配置URL为login.microsoftonline/[your-b2c-tenant].onmicrosoft/.well-known/openid-configuration
    • 进一步阅读:ASP.NET核心文档:Use multiple authentication schemes
  • 针对Web API的服务帐户AD应用请求访问令牌
  • 注意:确保在您的B2C租户下创建Azure AD应用。

    代码段从C#获取访问令牌

    using (var httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri("login.microsoftonline"); var content = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("grant_type", "client_credentials") , new KeyValuePair<string, string>("client_id", "[service account app id e.g. 10d635e5-7615-472f-8200-a81d5c87c0ca") , new KeyValuePair<string, string>("client_secret", "[client secret defined in the service account e.g. 5L2ZJOBK8GI1wRSgGFooHcBkAOUOj65lQd9DgJxQOrw=]") , new KeyValuePair<string, string>("scope", "[App ID URI of the web api azure ad app]/.default e.g. my-b2c-tenant.onmicrosoft/my-azure-ad-ap/.default") }); var requestResult = await httpClient.PostAsync("/[your b2c tenant].onmicrosoft/oauth2/v2.0/token", content); var contentResult = await requestResult.Content.ReadAsStringAsync(); var json = JObject.Parse(contentResult); var accessToken = (string)json["access_token"]; }

    App ID URI

    您可能希望定义一些自定义声明来保护Web API。请参阅'Application Permissions' here。

  • 修改Web API Azure AD App上的应用程序清单

    { "appRoles": [{ "allowedMemberTypes": [ "Application" ], "displayName": "Some display nane", "id": "[create a new guid]", "isEnabled": true, "description": "Allow the application to _____ as itself.", "value": "the-blah-role" } ] }
  • 将服务帐户Azure AD App权限授予定义的自定义应用程序权限

  • 授予服务帐户的权限将在roles声明中返回:

    { "roles": [ "the-blah-role" ] }

    请投赞成票the user voice feedback item以使

    更多推荐

    无头身份验证Azure AD B2C

    本文发布于:2023-11-28 09:07:56,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1641788.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:无头   身份验证   Azure   AD   B2C

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!