【问题标题】:Getting access token for an api protected by B2C, using custom policies使用自定义策略获取受 B2C 保护的 api 的访问令牌
【发布时间】:2021-04-11 03:57:32
【问题描述】:

我有一个使用 ADB2C 身份验证保护的 api。我需要通过自定义策略调用这个 api。我遵循文档enter link description here 并添加了两个技术配置文件作为自我断言配置文件的验证技术配置文件。

我收到以下技术配置文件返回的访问令牌:

<TechnicalProfile Id="SecureREST-AccessToken">
      <DisplayName></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://login.microsoftonline.com/{tenant id here}/oauth2/v2.0/token</Item>
        <Item Key="AuthenticationType">Basic</Item>
        <Item Key="SendClaimsIn">Form</Item>
      </Metadata>
      <CryptographicKeys>
        <Key Id="BasicAuthenticationUsername" StorageReferenceId="B2C_1A_SecureRESTClientId" />
        <Key Id="BasicAuthenticationPassword" StorageReferenceId="B2C_1A_SecureRESTClientSecret" />
      </CryptographicKeys>
      <InputClaims>
        <InputClaim ClaimTypeReferenceId="grant_type" DefaultValue="client_credentials" />
        <InputClaim ClaimTypeReferenceId="scope" DefaultValue="{app id uri for protected resource}/.default" />
      </InputClaims>
      <OutputClaims>
        <OutputClaim ClaimTypeReferenceId="bearerToken" PartnerClaimType="access_token" />
      </OutputClaims>
      <UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
    </TechnicalProfile>

然后使用以下配置文件进行其余的 api 调用:

<TechnicalProfile Id="UserMigrationViaLegacyIdp">
                <DisplayName>REST API call to communicate with Legacy IdP</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://99a0a14a6402.ngrok.io/api/Identity/SignUpAsync
        </Item>
                    <Item Key="AuthenticationType">Bearer</Item>
                    <Item Key="SendClaimsIn">Header</Item>
                    <Item Key="AllowInsecureAuthInProduction">false</Item>
        <Item Key="UseClaimAsBearerToken">bearerToken</Item>


      </Metadata>
                <InputClaims>
                    <InputClaim ClaimTypeReferenceId="bearerToken"/>
      </InputClaims>
                <OutputClaims>
                    
                    <OutputClaim ClaimTypeReferenceId="phonePresent"/>

                </OutputClaims>
                <UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
            </TechnicalProfile>

但是,返回的访问令牌中缺少范围,因此 api 上的令牌验证失败。

我获取访问令牌的调用是否缺少任何内容?

【问题讨论】:

    标签: azure-ad-b2c azure-ad-b2c-custom-policy


    【解决方案1】:

    对于客户端凭据授予流程,API 权限必须创建为角色(请参阅How to: Add app roles to your application and receive them in the token),然后授予管理员同意(请参阅Admin consent button)。

    因此,不记名令牌包含 roles 声明,而不是 scp 声明。

    API 应用程序使用此roles 声明检查访问(请参阅Verify app roles in APIs called by daemon apps)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多