Created
May 25, 2017 15:38
-
-
Save aruprakshit/b4d04a962d1d1ffefc2859e19db083bd to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/kubofub
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<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 | |
}) | |
.then( | |
function(response) { | |
if (response.status !== 200) { | |
console.log('Looks like there was a problem. Status Code: ' + | |
response.status); | |
return; | |
} | |
// Examine the text in the response as JSON | |
response.json().then(function(data) { | |
console.log(data); | |
}); | |
} | |
) | |
.catch(function(err) { | |
console.log('Fetch Error :-S', err); | |
}); | |
} | |
requestForAuthToken('https://oauth.brightcove.com/v4/access_token', 'client_id', 'client_secre'); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment