question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CORs error when making get requests Github API

See original GitHub issue

Describe the issue I’m trying to authenticate over OAUTH API using Axios. The initial request is just a simple GET to get the auth token.

…from origin ‘http://localhost:3001’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

I can use an href link and it works totally fine. What could be the issue here?

Example Code

  axios.get(
    "https://github.com/login/oauth/authorize?client_id=$ID"
  ).then((res) => { console.log(res) })

Expected behavior, if applicable A clear and concise description of what you expected to happen.

Environment:

  • Axios Version 0.19beta
  • OS: OSX 10.13.4]
  • Browser chrome
  • Browser Version latest
  • Additional Library Versions react Additional context/Screenshots Add any other context about the problem here. If applicable, add screenshots to help explain.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

8reactions
Zohaad97commented, Apr 13, 2019

Try to set headers in your HTTP request. See the example code

axios.get('https://google.com', {
 headers: {
   "Access-Control-Allow-Origin": "*"
 }
});
0reactions
snawazcommented, Jan 27, 2020

@moyid :

However, the OAuth request can work as a link, it would return the code by appending it to the current URL, and then you can get the code from the URL by using regex – this can be one of the few hacky solutions to this problem!

Could you please elaborate on this a bit more? Or url to an example would be great help. 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

GitHub API CORS Policy - Stack Overflow
I'm using jQuery and ajax to do a get request to the GitHub API but after I refresh about 3 ...
Read more >
New to JavaScript? You'll Run Into This Annoying Error When ...
If you're new to JavaScript or web programming in general, it's inevitable that you're going to run into something called a CORS error,...
Read more >
Fixing Common Problems with CORS and JavaScript
Tutorial: This post walks through troubleshooting and fixing common problems associated with calling REST APIs from JavaScript.
Read more >
What Is a CORS Error and How to Fix It (3 Ways) - Bannerbear
A CORS error is common when making an HTTP request to another origin. You can get rid of it using one of the...
Read more >
Cross-Origin Resource Sharing (CORS) - MDN Web Docs
For security reasons, browsers restrict cross-origin HTTP requests initiated from scripts. For example, XMLHttpRequest and the Fetch API ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found