I am confused on how to use authorization code flow using the Azure.Identity library. Here is a code sample taken from there site (https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/dev/docs/tokencredentials.md).
string[] scopes = {"User.Read"};
AuthorizationCodeCredential authorizationCodeCredential = new AuthorizationCodeCredential(tenantId, clientId, clientSecret, authCode);
GraphServiceClient graphClient = new GraphServiceClient(authorizationCodeCredential, scopes);
User me = await graphClient.Me.Request()
.GetAsync();
The problem is the generated token and refresh token are completely hidden so it can't be reused on future requests. Running this exact code again yields an error because auth codes cannot be used twice. My questions are:
- The code above shows how to generate a token based on the provided auth code. How can I reuse this token for future transactions without providing another auth code?
- If the token expires, how to refresh the token? The docs does not talk about this at all.