Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
JS Bin // source
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script type="text/javascript">
function base64Encode(client_id, client_secret) {
return window.btoa(client_id + ":" + client_secret);
function requestForAuthToken(url, client_id, client_secret) {
var headers = new Headers({
'Authorization': 'Basic ' + base64Encode(client_id, client_secret),
'Content-Type': 'application/x-www-form-urlencoded'
fetch(url, {
method: 'post',
body: 'grant_type=client_credentials',
mode: "no-cors",
headers: headers
function(response) {
if (response.status !== 200) {
console.log('Looks like there was a problem. Status Code: ' +
// Examine the text in the response as JSON
response.json().then(function(data) {
.catch(function(err) {
console.log('Fetch Error :-S', err);
requestForAuthToken('', 'client_id', 'client_secre');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment