how can I get refresh token

前端 未结 2 1741
感动是毒
感动是毒 2021-02-09 01:10

i learn this code sample :https://github.com/Azure-Samples/active-directory-dotnet-graphapi-web ,and yes ,i can get access token in AuthorizationCodeReceived : Authenticati

2条回答
  •  青春惊慌失措
    2021-02-09 02:16

    If you looking for a persistent mechanism, you can simply use TokenCache.Serialize()

    Here's how I did it:

    First, get the token and serialize the cache token

    AuthenticationContext authContext = new AuthenticationContext($"https://login.microsoftonline.com/{Tenant}");
    var authResult = authContext.AcquireTokenAsync(resource, ClientId, new Uri("https://login.microsoftonline.com/common/oauth2/nativeclient"), new PlatformParameters(PromptBehavior.SelectAccount)).Result;
    byte[] blobAuth = authContext.TokenCache.Serialize();
    

    Then, load the cached bytes

    AuthenticationContext authContext = new AuthenticationContext($"https://login.microsoftonline.com/{tenant}/");
    authContext.TokenCache.Deserialize(blobAuth);
    var res = authContext.AcquireTokenSilentAsync(resource, clientId).Result;
    

提交回复
热议问题