【问题标题】:How to request a refresh token with identityserver4如何使用 identityserver4 请求刷新令牌
【发布时间】:2017-07-26 16:01:02
【问题描述】:

我有 IdentityServer 和一个使用资源所有者流程的单独 WebApi 项目。

当我请求一个令牌时,该令牌被发出并可用于访问 WebApi。所以我假设 IdentityServer 设置正确,WebApi 项目也设置正确。

username=user1
password=user1password
grant_type=password
client_id=myClientId
client_secret=myClientSecret
scope=api1

现在,当我将授权类型更改为 refresh 并将范围更改为 offline_access 时,我会得到一个刷新令牌。然后我使用刷新令牌获取访问令牌,但是当我使用访问令牌请求 WebApi 时,它被拒绝。

出现错误

the audience is invalid

我怀疑这是因为我要求的是offline_access 范围,而不是WebApi 项目所期望的api1 范围。如何获取可与范围 api1 一起使用的刷新令牌?

【问题讨论】:

    标签: asp.net asp.net-identity identityserver4


    【解决方案1】:
     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
                    });
    

    【讨论】:

      猜你喜欢
      • 2019-12-23
      • 2018-07-07
      • 2017-10-25
      • 2020-06-02
      • 2019-03-23
      • 2016-01-05
      • 2020-09-12
      • 2017-03-30
      • 2020-02-20
      相关资源
      最近更新 更多