2017-07-26 75 views
0

我有使用資源所有者流的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的刷新令牌?

回答

0
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 
       }); 
相關問題