2017-07-26 17 views
0

私はIdentityServerと、リソース所有者フローを使用する別のWebApiプロジェクトを持っています。identityserver4でリフレッシュトークンを要求する方法

以下のようにトークンを要求すると、トークンが発行され、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 

私は、私が代わりにWEBAPIプロジェクトが期待API1スコープのoffline_access範囲を求めていますので、それはだ疑いで

。スコープ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 
       }); 
関連する問題