我有一个使用ADAL进行身份验证的桌面应用程序,该应用程序向API Management Azure服务上的API发出请求。在将代码迁移为使用MSAL之后,API管理返回401,表示我的令牌无效。我看到的是监视请求的唯一区别是ADAL向此端点/tenantID/oauth2/token
和MSAL /tenantID/oauth2/v2.0/token
发出了请求。
在我的API管理中,我有此政策:
<validate-jwt header-name="Authorization" failed-validation-httpcode="401" failed-validation-error-message="Unauthorized. Access token is missing or invalid. AAD" require-expiration-time="false">
<openid-config url="https://login.microsoftonline.com/tenantID/.well-known/openid-configuration" />
</validate-jwt>
我尝试将众所周知的url更改为v2.0端点,但收到相同的错误。如何使用MSAL验证令牌?
从doc中的注,将众所周知的URL更改为v2.0时,可能需要使用common
而不是tenantID
。
<validate-jwt header-name="Authorization" failed-validation-httpcode="401" failed-validation-error-message="Unauthorized. Access token is missing or invalid.">
<openid-config url="https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration" />
<required-claims>
<claim name="aud">
<value>{Application ID of backend-app}</value>
</claim>
</required-claims>
</validate-jwt>
还要确保您正确执行此link中的步骤10:
如果使用v2端点,请使用为后端应用创建的范围 在默认范围字段中。另外,请确保为 在您的accessTokenAcceptedVersion属性中将
2
application manifest。