如何请求身份识别服务器4的刷新令牌
问题描述:
我有使用资源所有者流的IdentityServer和单独的WebApi项目。如何请求身份识别服务器4的刷新令牌
当我像下面一样请求一个令牌时,令牌被发出并且可以用来访问WebApi。所以我假设IdentityServer安装正确,并且WebApi项目也正确设置。
username=user1
password=user1password
grant_type=password
client_id=myClientId
client_secret=myClientSecret
scope=api1
现在,当我更改授予类型刷新和范围到offline_access我得到一个刷新令牌。然后我使用刷新令牌来获取访问令牌,但是当我使用访问令牌来请求WebApi时,它会被拒绝。
有了错误
the audience is invalid
我怀疑这是因为我要求的offline_access范围,而不是其中的WebAPI项目预计API1范围。我如何获得可用于范围api1的刷新令牌?
答
var model = {
client_id: "myClientId",
client_secret: "myClientSecret",
scope: "api1 offline_access",
token_type: "Bearer", //Optional
grant_type: "refresh_token",
refresh_token: "your refresh token"
};
//this is most important step when to use refresh token
var base64 = btoa(model.client_id + ":" + model.client_secret);
//and your request here
this.$http({
method: "POST",
url: "/connect/token",
headers: {
'content-type': "application/x-www-form-urlencoded",
'Authorization': "Basic " + base64
},
data: jQuery.param(model)
})
.then(
response => {
//success
},
response => {
//logout
});