Skip to content

Instantly share code, notes, and snippets.

@aruprakshit
Created May 25, 2017 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aruprakshit/b4d04a962d1d1ffefc2859e19db083bd to your computer and use it in GitHub Desktop.
Save aruprakshit/b4d04a962d1d1ffefc2859e19db083bd to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/kubofub
<!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