【问题标题】:Get the Azure AD B2C scope in the custom policy在自定义策略中获取 Azure AD B2C 范围
【发布时间】:2018-08-24 10:26:12
【问题描述】:

我尝试创建自定义策略,并且希望获得一些声明并将其发送到我的 REST API。 我的 API 是通过电子邮件、givenName 等调用的……但通过查询字符串(如 client_id、resource_id 和大多数范围)传递的声明为空。

我在这里找到了获取 client_id 的解决方法:Get the Azure AD B2C Application client id in the custom policy

但我没有发现关于范围的任何信息。

这是我的 REST API 声明提供程序:

<ClaimsProvider>
    <DisplayName>REST API</DisplayName>
    <TechnicalProfiles>
        <TechnicalProfile Id="AzureFunction-SendClaims">
            <DisplayName>Send Claims</DisplayName>
            <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.RestfulProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
            <Metadata>
                <Item Key="ServiceUrl">https://XXXX.azurewebsites.net/api/XXXX</Item>
                <Item Key="AuthenticationType">None</Item>
                <Item Key="SendClaimsIn">Body</Item>
            </Metadata>
            <InputClaims>
                <InputClaim ClaimTypeReferenceId="givenName"/>
                <InputClaim ClaimTypeReferenceId="client_id" PartnerClaimType="clientId" DefaultValue="{OIDC:ClientId}"/>
                <InputClaim ClaimTypeReferenceId="resource_id"/>
                <InputClaim ClaimTypeReferenceId="email"/>
                <InputClaim ClaimTypeReferenceId="otherMails"/>
                <InputClaim ClaimTypeReferenceId="grant_type"/>
                <InputClaim ClaimTypeReferenceId="scope"/>
            </InputClaims>
        </TechnicalProfile>
    </TechnicalProfiles>
</ClaimsProvider>

【问题讨论】:

    标签: azure azure-ad-b2c


    【解决方案1】:

    我认为没有办法获得范围。 您可以在 B2C 政策here 中查看可访问的声明和属性列表

    【讨论】:

    【解决方案2】:

    Scope 声明已添加到 OpenId 连接声明解析器中:

    &lt;InputClaim ClaimTypeReferenceId="Scope" DefaultValue="{OIDC:Scope}"/&gt;

    我已经使用过它并且它可以工作,但它没有被添加到OpenID Connect-specific claims的文档中

    【讨论】:

      【解决方案3】:

      在您的自定义策略中,以简单明了的方式随意发送变量。传递范围的上下文是当您从用户会话调用 REST API 时,因此您必须请求自定义策略令牌。

      您可以通过两种方式来实现,使用 MSAL 库(我更喜欢这个):https://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-web-api-call-api-acquire-token?tabs=aspnetcore

      或者,通过直接调用自定义策略并在范围部分的字符串查询中,即

      scope=openid profile offline_access https://yourtenant.onmicrosoft.com/demoapi/demo.read https://kytos.onmicrosoft.com/demoapi/demo.write

      不要忘记 html 编码 scope=openid%20profile%20offline_access%20https%3A%2F....

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多