My goal is managing user’s access token by refresh token. Because, I don’t want to require login(interactive) after once login.
And, I need to personal user token. So, I use “AcquireTokenInteractive”
I hope to get refresh token when I get access token. But, I can’t get it.
It’s my code.
I want to request token by c#
// var scopes = new string[] { "User.Read", "Mail.Read", "offline_access" }; // I tried
var scopes = new string[] { "https://graph.microsoft.com/.default offline_access" };
try
{
var app = PublicClientApplicationBuilder.Create(clientId)
.WithRedirectUri(redirectUri)
.WithTenantId(tenantId)
.Build();
var authResult = app.AcquireTokenInteractive(scopes)
.ExecuteAsync().Result;
var accounts = app.GetAccountsAsync("refresh_token").Result;
token = authResult.AccessToken;
var token2 = authResult.AuthenticationResultMetadata.TokenEndpoint;
And also, In my Azure app added api/permissions “User.Read, offline_access, Mail.Read” .
Some document said, In .Net environment can’t get refresh token by security reasons. So, if I want to use refresh token. Do I need to use cache?
It’s refer to this ask’s answer that
- How to get refresh token in MSAL .Net C#
- Azure AD login using C#. Acquiring Refresh token and Access token
In sum, I guess the reason from my code and azure setting issue? Or Basically, I can’t get refresh token in my situation(like environment, security reason and so on)?