How to add additional parameter when sign in with Microsoft OAuth using Laravel League/oAuth

Surajit Basak 6 Reputation points
2022-01-19T10:15:49.613+00:00

Hi, I have a Laravel application which will sync doctor appointment in Microsoft Calendar.

Laravel package used:

  1. "league/oauth2-client": "^2.6",
  2. "microsoft/microsoft-graph": "^1.49"

Now, my situation is doctor is signed in https://tenant.project.dev and he needs to use microsoft consent screen(oAuth) to allow our application to sync patient appointment to his microsoft calendar.

Now redirect url is saved in Azure portal as https://project.dev.

What I want is when microsoft redirects to that redirect url it will add additional parameters with like tenant_id=1&doctor_id=2&referrer_url=https://tenant.project.dev or parameter with encrypted request so, that I can decrypt it later in my redirect route.

Example:

https://project.dev?code=xxxxx&state=xxxx&params=xxxxxx

Can it be possible? Please help me.

Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. CarlZhao-MSFT 46,371 Reputation points
    2022-01-25T07:45:36.007+00:00

    Hi @Surajit Basak

    Did you mean the authorization code?

    This requires you to request the URL in your browser, then it will jump to the Microsoft login page, you need to log in with the doctor user, and finally you will get an encrypted authorization code in the browser address bar.

    https://login.microsoftonline.com/{doctor tenant id}/oauth2/v2.0/authorize?  
    client_id={client id}  
    &response_type=code  
    &redirect_uri=https://project.dev  
    &response_mode=query  
    &scope=https://graph.microsoft.com/.default  
    &state=12345  
    

    168213-image.png

    168174-image.png


    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.


  2. Surajit Basak 6 Reputation points
    2022-01-26T15:55:29.89+00:00

    Finally I have found the solution for this problem after so many research.

    Need to use an array parameter when trying to get authorization url using getAuthorizationUrl method. Like below:

    oauthClient = new GenericProvider([
        'clientId'                => config('azure.appId'),
        'clientSecret'            => config('azure.appSecret'),
        'redirectUri'             => config('azure.redirectUri'),
        'urlAuthorize'            => config('azure.authority') . config('azure.authorizeEndpoint'),
        'urlAccessToken'          => config('azure.authority') . config('azure.tokenEndpoint'),
        'urlResourceOwnerDetails' => '',
        'scopes'                  => config('azure.scopes')
    ]);
    
    authUrl = oauthClient->getAuthorizationUrl([
        'state' => Helper::CustomEncode(json_encode(
            [
                "referrer" => _SERVER["HTTP_REFERER"],
                "param1" => "new value",
                "param2" => "another value",
                "param3" => "even another value",
            ]
        ))
    ]);
    
    // Redirect to AAD signin page
    return redirect()->away(authUrl);
    

    N.B.: The dollar sign is not allowed when submitting this comment.


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.