AzureAD / azure-activedirectory-library-for-js

The code for ADAL.js and ADAL Angular has been moved to the MSAL.js repo. Please open any issues or PRs at the link below.
https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/maintenance/adal-angular
Apache License 2.0
627 stars 374 forks source link

Access token error for graph.microsoft.com #787

Closed mw-tim closed 5 years ago

mw-tim commented 6 years ago

I am trying to get a list of users from active directory, I am getting my access token using:

authContext.acquireToken(`${tenantid}`, function(errdesc, token, error){
    onst auth = {
            headers: { 
                'Authorization': `Bearer ${token}`
             }
        }

        axios.get('https://graph.microsoft.com/v1.0/users/', auth)
        .then(function (response) {

        })
        .catch(function (error) {
            // handle error
        })
});

But when I request the users I get a 401 unauthorized

{
  "error": {
    "code": "InvalidAuthenticationToken",
    "message": "Access token validation failure.",
    "innerError": {
      "request-id": "dc100a3d-6fcf-49a2-92ff-3b3a1cda8cdd",
      "date": "2018-07-26T14:06:07"
    }
  }
}

Any help would be great.

nehaagrawal commented 6 years ago

@mw-tim Not sure why you are passing the tenantid to acquireTokenApi(). It should be the resource name. In your case, it's the 'https://graph.microsoft.com/v1.0/users/'. Can you please try this and see if it works?

rohitnarula7176 commented 5 years ago

@mw-tim Closing this issue due to lack of response. Please reopen if it is not resolved for you.