Azure ad b2c 使用自定义策略获取受B2C保护的api的访问令牌

Azure ad b2c 使用自定义策略获取受B2C保护的api的访问令牌,azure-ad-b2c,azure-ad-b2c-custom-policy,Azure Ad B2c,Azure Ad B2c Custom Policy,我有一个使用ADB2C身份验证保护的api。我需要通过自定义策略调用此api。我遵循文档,添加了两个技术配置文件,作为自断言配置文件的验证技术配置文件 我正在获取由以下技术配置文件返回的访问令牌: <TechnicalProfile Id="SecureREST-AccessToken"> <DisplayName></DisplayName> <Protocol Name="Proprietary&

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

我正在获取由以下技术配置文件返回的访问令牌:

<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>
<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>

https://login.microsoftonline.com/{此处的租户id}/oauth2/v2.0/token
基本的
形式
然后使用以下配置文件进行rest api调用:

<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>
<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>

REST API调用与遗留IdP通信
https://99a0a14a6402.ngrok.io/api/Identity/SignUpAsync
持票人
标题
假的
比尔托肯
但是,返回的访问令牌中缺少作用域,因此api上的令牌验证失败


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

对于客户端凭据授予流,必须将API权限创建为角色(请参阅),然后授予管理员许可(请参阅)

因此,承载令牌包含
角色
声明,而不是
scp
声明


API应用程序使用此
角色
声明检查访问权限(请参阅)。

对于客户端凭据授予流,必须将API权限创建为角色(请参阅),然后授予管理员同意(请参阅)

因此,承载令牌包含
角色
声明,而不是
scp
声明

API应用程序使用此
角色
声明检查访问(请参阅)