Get refresh token with Azure AD V2.0 (MSAL) and Asp .Net Core 2.0

后端 未结 3 407
说谎
说谎 2020-12-17 22:14

I\'ve got access_token from Azure Ad V2.0 endpoint to call Graph Api. But I have to do some actions in the api on behalf of user. So I need refresh_token to renew my access_

3条回答
  •  清歌不尽
    2020-12-17 23:20

    TokenCache is basically a JSON object which is served as byte array when you call SerializeMsalV3(). When you convert byte array to string, you will see both access token and refresh token. Then you can make a HTTP request to \token endpoint with this refresh token and grant_type: "refresh_token" body parameters.

    IConfidentialClientApplication capp =
                        ConfidentialClientApplicationBuilder.Create(myClientId)
                            .WithClientSecret(myclientSecret)
                            .Build();
    
        capp.UserTokenCache.SetAfterAccess((TokenCacheNotificationArgs args) =>
        {
           exchangeTokenCacheV3Bytes = args.TokenCache.SerializeMsalV3();
           string jsonString = System.Text.Encoding.UTF8.GetString(exchangeTokenCacheV3Bytes);
        });
    

提交回复
热议问题