Skip to content

Instantly share code, notes, and snippets.

@arufian
Created December 23, 2022 09:57
Show Gist options
  • Save arufian/35b7734880230365565c131ab5e22e91 to your computer and use it in GitHub Desktop.
Save arufian/35b7734880230365565c131ab5e22e91 to your computer and use it in GitHub Desktop.
a fetch function with oauth 2.0 capability
function fetchWithAuth(url, options) {
var accessToken = '<your access token>';
if (!options) {
options = {};
}
if (!options.headers) {
options.headers = new Headers();
}
options.headers.append('Authorization', 'Bearer ' + accessToken);
return fetch(url, options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment