我有 IdentityServer 和一个使用资源所有者流程的单独的 WebApi 项目。
当我请求如下 token 时, token 将被颁发并可用于访问 WebApi。所以我假设 IdentityServer 已正确设置,并且 WebApi 项目也已正确设置。
username=user1
password=user1password
grant_type=password
client_id=myClientId
client_secret=myClientSecret
scope=api1
现在,当我将授予类型更改为刷新并将范围更改为离线访问时,我会获得刷新 token 。然后,我使用刷新 token 来获取访问 token ,但是当我使用访问 token 请求 WebApi 时,它被拒绝。
有错误
the audience is invalid
我怀疑这是因为我要求offline_access范围而不是WebApi项目期望的api1范围。如何获取可与范围 api1 一起使用的刷新 token ?
最佳答案
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
});
关于asp.net - 如何使用 Identityserver4 请求刷新 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45316535/