Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.