【发布时间】:2017-07-19 22:58:31
【问题描述】:
我有一个 Azure 应用服务,我在该服务上启用了身份验证/授权并将 AD 配置为身份验证提供程序。
服务上所有/.auth路由都存在,我可以登录。登录成功后我可以调用/.auth/me获取access_token。响应如下:
[
{
"access_token": "AQABAAAAAA...Gni4EiQgAA",
"expires_on": "2017-02-28T19:17:08.0000000Z",
"id_token": JWT TOKEN
...
}
]
然后我在授权承载标头中使用access_token 从服务请求数据。
"Authorization": "Bearer " + "AQABAAAAAA...Gni4EiQgAA"
我的服务返回以下错误
IDX10708: 'System.IdentityModel.Tokens.JwtSecurityTokenHandler' cannot read this string: 'AQABAAAAAA...Gni4EiQgAA'.
The string needs to be in compact JSON format, which is of the form: '<Base64UrlEncodedHeader>.<Base64UrlEndcodedPayload>.<OPTIONAL, Base64UrlEncodedSignature>'.
根据this discussion,access_token 旨在用作承载令牌。我还阅读了here access_token 应该是 base64 编码的,但事实并非如此。
此外,如果我使用 id_token 作为 Bearer 令牌,则身份验证按预期工作(id_token 是 JWT 格式)。
编辑
当我按照here 的描述手动实现 Oauth 流程时,我会收到正确的 JWT access_token。
GET
https://login.microsoftonline.com/common/oauth2/authorize?client_id=client_id&response_type=code&redirect_uri=redirect_uri
紧随其后
POST
https://login.microsoftonline.com/common/oauth2/token
grant_type=authorization_code
client_id=client_id
code=CODE FROM ABOVE
redirect_uri=redirect_uri
resource=resource
client_secret=client_secret
RESPONSE
{
"access_token": JWT TOKEN,
"token_type": "Bearer",
...
}
【问题讨论】:
-
您在后端服务器上的设置是什么?
标签: azure azure-web-app-service