I am trying to use the Authorization Code Grant with my site. I am able to get the code back from the oauth authorize redirect (i.e. login to Genesys Cloud). But when I make the post to https://login.mypurecloud.com/oauth/token I receive the following error:
Access to XMLHttpRequest at 'https://login.mypurecloud.com/oauth/token' from origin 'https://localhost:8081' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I am using Vue for the site and Axios to make the requests to APIs. Here is my code:
const token = Buffer.from(`${client_id}:${client_secret}`, 'utf8').toString('base64')
const getOAuthToken = () => axios({
method: "post",
url: "https://login.mypurecloud.com/oauth/token",
data: {
grant_type: "authorization_code",
code: storedCode, //from the query string parameters sent to this url
redirect_uri : "https://localhost:8081/login"
},
headers: {"Content-Type" : "application/x-www-form-urlencoded",
"Authorization": `Basic ${token}`}
});
getOAuthToken()
.then(response => {
this.info = response;
})
.catch(error => {
this.errormsg = error;
console.log(error);
})
I have posted this to httpbin and the headers look correct:
"headers": { "Accept": "application/json, text/plain, /", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "en-US,en;q=0.9", "Authorization": "Basic NWQ4MzhhNWYtYmZjZS00NTRlLTg5ZWItYzgwNWFkYTMwZTQwOkNsQkxTdUZFQVRZQ2JQN2ZBajVoTUc4bl8wYk1YYjdWUmVNWjlCc2hQZUE=", "Content-Length": "134", "Content-Type": "application/x-www-form-urlencoded", "Host": "httpbin.org", "Origin": "https://localhost:8081", "Referer": "https://localhost:8081/login", "Sec-Fetch-Dest": "empty", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Site": "cross-site", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36", "X-Amzn-Trace-Id": "Root=1-5ec987cd-81f44c7eab9d49e48e0850a5" }
Lastly, my redirect URIs in the OAuth Client are:
https://localhost:8081
https://localhost:8081/
https://localhost:8081/login