在自定义策略中获取Azure AD B2C范围

时间:2018-03-15 14:39:58

标签: azure azure-ad-b2c

我尝试创建自定义策略,我想获得一些声明并将其发送到我的REST API。 我的API是通过email,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>

3 个答案:

答案 0 :(得分:1)

范围声明已添加到OpenId connect声明解析器:

<InputClaim ClaimTypeReferenceId="Scope" DefaultValue="{OIDC:Scope}"/>

我已经使用了它并且可以使用,但是尚未将其添加到OpenID Connect-specific claims

的文档中

答案 1 :(得分:0)

我认为没有办法获得范围。 您可以在B2C政策here

中查看可供访问的声明和媒体资源列表

答案 2 :(得分:0)

在您的自定义策略中,可以自由,安全地以简单的方式发送变量。传递作用域的上下文是从用户会话中调用REST API时,因此必须请求自定义策略令牌。

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

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

scope = openid个人资料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 ....

相关问题