bilalmetla
bilalmetla

Reputation: 155

Refresh_token using oauth.io

Hi I am student of Computer Science and doing some experiments on oauth.io. but i am facing problem to get refresh_token after getting code successfully. After getting the code i am writing the follwing line of code but its giving me Internal server error..

The code is

$.ajax("https://oauth.io/auth/access_token", {
    type: "post",
    data: {
        code: result.code,
        key: '5WeOrrR3tP6RyShR1',
        secret: '2_q3tb_D_qgDwSGpt' },
    success: function (data) { 
        console.log("result", data); 
    }   
});

Which url used to get refresh_token? please someone help me.

thanks

Upvotes: 1

Views: 430

Answers (1)

bumpmann
bumpmann

Reputation: 685

there was a bug recently in the js sdk when you set the response type server-side (to get the code & refresh_token), so you may have to redownload oauth.js if you use a static version.

I guess your jquery code is server side (because of the nodejs tag and the use of a code), but i had an error "no transport" that i fixed with a new XMLHttpRequest. Here is my full test:

var jsdom = require('jsdom').jsdom;
var win = jsdom().createWindow();
var $ = require('jquery')(win);
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;

$.support.cors = true;
$.ajaxSettings.xhr = function () {
    return new XMLHttpRequest;
}

$.ajax("https://oauth.io/auth/access_token", {
    type: "post",
    data: {
        code: process.argv[2],
        key: 'xxxxxxxxxxxx',
        secret: 'yyyyyyyyyyyy' },
    success: function (data) {
        console.log("result", data);
    },
    error: function() {
        console.error(arguments);
    }
});

and my result looks like:

{ access_token: 'xxxxxxxxxxx',
  request:
   { url: '{{instance_url}}',
     required: [ 'instance_url' ],
     headers: { Authorization: 'Bearer {{token}}' } },
  refresh_token: 'yyyyyyyyyyyyy',
  id: 'https://login.salesforce.com/id/00Db0000000ZbGGEA0/005b0000000SSGXAA4',
  instance_url: 'https://eu2.salesforce.com',
  signature: 'zzzzzzzzzzzzz',
  state: 'random_string',
  provider: 'salesforce' }

Upvotes: 5

Related Questions