Skip to content

Instantly share code, notes, and snippets.

@chintanparikh
Forked from coffeejay/gist:15cb1f35637204aafd11
Last active August 29, 2015 14:25

Revisions

  1. chintanparikh revised this gist Jul 20, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gist.js
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ window.onload = function() {
    xhr.open('POST',
    'http://localhost:3000/oauth/token?' +
    'client_id=' + "7b529aed5e89c14bd45c4cb949f220e5bc4cc440003dd7604d3fc6ed43f29844" +
    '&client_secret=' + "48ec91d8b544bc13f6ddc2528a64105da385cbde6b4345972026eb3eaf8abd0a" +
    '&grant_type=' + "authorization_code" +
    '&redirect_uri=' + "https://hnjjholodahaklljjenjpfbkkghppdpk.chromiumapp.org/vyrtex-chrome-extension" +
    '&code=' + code);
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  2. chintanparikh revised this gist Jul 20, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gist.js
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ window.onload = function() {
    '&code=' + code);
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xhr.setRequestHeader('Accept', 'application/json');
    xhr.setRequestHeader('Accept', 'application/json');
    xhr.setRequestHeader('Authorization', 'Basic ' + btoa('7b529aed5e89c14bd45c4cb949f220e5bc4cc440003dd7604d3fc6ed43f29844' + ':' + '48ec91d8b544bc13f6ddc2528a64105da385cbde6b4345972026eb3eaf8abd0a'));
    xhr.onload = function () {
    if (this.status === 200) {
    var response = JSON.parse('"'+this.responseText+'"');
  3. chintanparikh revised this gist Jul 20, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion gist.js
    Original file line number Diff line number Diff line change
    @@ -12,13 +12,14 @@ window.onload = function() {
    function exchangeCodeForToken(code) {
    var xhr = new XMLHttpRequest();
    xhr.open('POST',
    'https://localhost:3000/oauth/access_token?' +
    'http://localhost:3000/oauth/token?' +
    'client_id=' + "7b529aed5e89c14bd45c4cb949f220e5bc4cc440003dd7604d3fc6ed43f29844" +
    '&client_secret=' + "48ec91d8b544bc13f6ddc2528a64105da385cbde6b4345972026eb3eaf8abd0a" +
    '&redirect_uri=' + "https://hnjjholodahaklljjenjpfbkkghppdpk.chromiumapp.org/vyrtex-chrome-extension" +
    '&code=' + code);
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xhr.setRequestHeader('Accept', 'application/json');
    xhr.setRequestHeader('Accept', 'application/json');
    xhr.onload = function () {
    if (this.status === 200) {
    var response = JSON.parse('"'+this.responseText+'"');
  4. chintanparikh renamed this gist Jul 20, 2015. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion gistfile1.txt → gist.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    window.onload = function() {
    $("#login").click(function(event) {
    chrome.identity.launchWebAuthFlow(
  5. @coffeejay coffeejay created this gist Jul 20, 2015.
    32 changes: 32 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@

    window.onload = function() {
    $("#login").click(function(event) {
    chrome.identity.launchWebAuthFlow(
    {'url': 'http://localhost:3000/oauth/authorize?client_id=7b529aed5e89c14bd45c4cb949f220e5bc4cc440003dd7604d3fc6ed43f29844&redirect_uri=https%3A%2F%2Fhnjjholodahaklljjenjpfbkkghppdpk.chromiumapp.org%2Fvyrtex-chrome-extension&response_type=code', 'interactive': true},
    function(redirect_url) {
    console.log(redirect_url);
    var code = redirect_url.substring(redirect_url.indexOf("=") + 1, redirect_url.length );
    exchangeCodeForToken(code);
    });
    });

    function exchangeCodeForToken(code) {
    var xhr = new XMLHttpRequest();
    xhr.open('POST',
    'https://localhost:3000/oauth/access_token?' +
    'client_id=' + "7b529aed5e89c14bd45c4cb949f220e5bc4cc440003dd7604d3fc6ed43f29844" +
    '&client_secret=' + "48ec91d8b544bc13f6ddc2528a64105da385cbde6b4345972026eb3eaf8abd0a" +
    '&redirect_uri=' + "https://hnjjholodahaklljjenjpfbkkghppdpk.chromiumapp.org/vyrtex-chrome-extension" +
    '&code=' + code);
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xhr.setRequestHeader('Accept', 'application/json');
    xhr.onload = function () {
    if (this.status === 200) {
    var response = JSON.parse('"'+this.responseText+'"');
    response = response.substring(0,response.indexOf('&'));
    access_token = response;
    console.log(access_token);
    }
    };
    xhr.send();
    }