title: Why am I getting an Unauthorized response with the Outlook API with Azure Active Directory?
body: <p>I'm creating a task that will retrieve the messages in outlook mail with Microsoft <strong>Azure</strong> Active Directory.</p>
  <p>I setup my azure account. Register an app, add certificate then add user to my AD. My signin method returns an access token which means signin is successful and pass the access token to outlook messages API. but the Outlook messages API returns unauthorize.</p>
  <p>Here is my scope: email Group.Read.All Mail.Read Mail.Read.Shared Mail.ReadBasic openid profile User.Read User.ReadBasic.All Mail.ReadWrite</p>
  <p>I used Laravel HTTP Client to send request. Hope anyone can help me, Im stuck on this problem for week</p>
  <pre><code>     public function __construct()
       {
            $this-&gt;params = [
               'client_id'       =&gt; env('OAUTH_APP_ID'),
               'scope'           =&gt; env('OAUTH_SCOPES'),
               'client_secret'   =&gt; env('OAUTH_APP_PASSWORD'),
               'username'        =&gt; 'xxxxxxxx@mytenant.onmicrosoft.com',
               'password'        =&gt; 'xxxxxxxx',
               'grant_type'      =&gt; 'password',
               'redirectUri'     =&gt; env('OAUTH_REDIRECT_URI'),
               'urlAuthorize'    =&gt; env('OAUTH_AUTHORITY').env('OAUTH_AUTHORIZE_ENDPOINT'),
               'urlAccessToken'  =&gt; env('OAUTH_AUTHORITY').env('OAUTH_TOKEN_ENDPOINT'),
               'urlResourceOwnerDetails' =&gt; '',
            ];
        }
        public function signin()
        {
            $url = 'https://login.microsoftonline.com/organizations/oauth2/v2.0/token';
            $response = Http::asForm()-&gt;post($url, $this-&gt;params);
            if($response-&gt;ok()){
                 $returnData = $response-&gt;json();
                 $mail_api = 'https://outlook.office.com/api/v2.0/me/messages';
                 $messagesResponse = Http::withToken($returnData['access_token'])-&gt;get($mail_api);
                 dd($messagesResponse);
            }
         }
  </code></pre>
  <p>Here is the response of my signin. I used Laravel HTTP client to send request.</p>
  <p><a href="https://i.stack.imgur.com/E1o8s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E1o8s.png" alt="enter image description here" /></a></p>
  <p>And for additinal info in my granted permission
  <a href="https://i.stack.imgur.com/tRGQj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tRGQj.png" alt="enter image description here" /></a></p>