Created
December 23, 2022 09:57
-
-
Save arufian/35b7734880230365565c131ab5e22e91 to your computer and use it in GitHub Desktop.
a fetch function with oauth 2.0 capability
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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