paolacl
paolacl

Reputation: 191

Failed to load https://login.microsoftonline.com/common/oauth2/v2.0/token

I'm trying to get a token using the Outlook REST API after I got the code from this url https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize

I used a POST request with axios but the issue is I got this error:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.

My Axios post is this:

return Axios({
    method: 'post',
    url: 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Access-Control-Allow-Origin':'*', Content-Type, origin, authorization, accept, client-security-token"
    },
    data: {
        'client_id': 'xxxxxx',
        'scope': 'calendars.readwrite',
        'code': encodeURIComponent('000000000'),
        'redirect_uri': encodeURIComponent('http://localhost:3000/storeprofile/xxxxxxxxx/outlook-scheduler'),
        'grant_type': 'authorization_code',
        'client_secret': encodeURIComponent('xxxxxxxxxx')
    };,
    responseType: 'json'
    }).then((response) => {
        console.log('token response: ', response);
    });

I get a 200 status but can't see the token I am supposed to get in the response. The response should be a json but still nothing.

Can someone please guide me? Thank you in advance!

Upvotes: 4

Views: 9777

Answers (1)

Gabriel Bleu
Gabriel Bleu

Reputation: 10204

When you register your app, you must setup the Redirect URI/URL, usually this url will be added to the CORS header.

doc : https://developer.microsoft.com/en-us/graph/docs/concepts/auth_overview#how-do-i-get-my-app-talking-to-azure-ad-and-microsoft-graph

Upvotes: 0

Related Questions