Graph API authentication skips over sign in steps

Dan 1 Reputation point
2022-06-09T16:16:24.243+00:00

Hi there,

I have creating an api connection with graph, specifically to get the refresh token.

When i send out the call for authorization it just skips over the sign-in steps. It returns a code but no token.

I followed 2 separate online tutorials and I have the same issue with both. Is it some settings that i am missing?

any help would be appreciated, thank you.

Dan

Microsoft Security Microsoft Graph
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 46,366 Reputation points
    2022-06-10T08:22:26.867+00:00

    Hi @Dan

    The official sample does not provide you with a web view to log in the user. You need to complete the user interaction flow in the browser to obtain the authorization code.

    The part of OAuth 2.0 authorization flow is as below:

    210195-image.png

    If you want to get an access token, I recommend you to use the graph SDK. However from my testing MSAL doesn't seem to expose refresh_token to developers, it only refreshes the token for you when your access token expires.

    using Microsoft.Identity.Client;  
    using Microsoft.Graph.Auth;  
      
    namespace test1 {  
    
        class Program  
      
        {      
            static async System.Threading.Tasks.Task Main(string[] args)  
            {  
                            string clientId = "{client id}";  
                            string clientSecret = "client secret";  
                            string redirectUri = "redirect url";  
                            string authority = "https://login.microsoftonline.com/{tenant id}";  
                            string authorizationCode = "auth code";  
      
                            string[] scopes = new string[] { "Mail.Read openid profile email offline_access" };  
      
                            IConfidentialClientApplication app = ConfidentialClientApplicationBuilder  
                                .Create(clientId)  
                                .WithRedirectUri(redirectUri)  
                                .WithClientSecret(clientSecret)  
                                .WithAuthority(authority)  
                                .Build();  
                              
                           AuthorizationCodeProvider auth = new AuthorizationCodeProvider(app, scopes);  
      
                var authResult = await app.AcquireTokenByAuthorizationCode(scopes, authorizationCode).ExecuteAsync();  
      
                Console.WriteLine(authResult.AccessToken);  
                 
            }  
      
        };  
    }  
    

    210160-image.png

    Of course you can use postman to request the /token endpoint to get the refresh token.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.