我有一个 API,可以使用 TTL 为 1 小时的不记名令牌访问该 API。我需要通过 ADB2C 使用这个 API。
根据 Microsoft 文档,不记名令牌是从策略密钥 B2C_1A_B2cRestClientAccessToken 中读取的:
<TechnicalProfile Id="REST-API-SignUp">
<DisplayName>Validate user's input data and return loyaltyNumber claim</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://your-app-name.azurewebsites.NET/api/identity/signup</Item>
<Item Key="AuthenticationType">Bearer</Item>
<Item Key="SendClaimsIn">Body</Item>
</Metadata>
<CryptographicKeys>
<Key Id="BearerAuthenticationToken" StorageReferenceId="B2C_1A_B2cRestClientAccessToken" />
</CryptographicKeys>
</TechnicalProfile>
但是,策略密钥 (B2C_1A_B2cRestClientAccessToken) 是静态的,而在我的例子中,每次 ADB2C 需要使用 API 时都需要检索不记名令牌。我该如何实现这个目标?
下面的微软文档似乎解释了如何获取访问令牌并在每次需要使用API时使用。我还没有测试它,但它似乎完全被覆盖了: