Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Oauth using Meteor and Backbone

View meteor-oauth-client.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
var AUTH_URL = "https://api.glitch.com/oauth2/authorize?response_type=code&client_id=000yourclientid000&redirect_uri=http://yoursitehere/oauth/&scope=identity";
 
var Auth_Router = Backbone.Router.extend({
routes: {
"": "root",
"oauth/?code=:code": "auth"
},
root: function () {},
auth: function (code) {
Meteor.call('authenticate', code, function (error, result) {
//do something with returned data here
});
this.navigate('');
}
});
 
 
Meteor.startup(function () {
var router = new Auth_Router();
Backbone.history.start({pushState: true});
});
View meteor-oauth-client.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
Meteor.methods({
authenticate: function (auth_code) {
this.unblock();
var res = Meteor.http.call("POST", "https://api.glitch.com/oauth2/token",
{params: {
grant_type : 'authorization_code',
code: auth_code,
client_id : secrets.glitch.client_id,
client_secret : secrets.glitch.client_secret,
redirect_uri : secrets.glitch.redirect_uri
}, headers: {
"content-type": "application/x-www-form-urlencoded"
}});
if (res.statusCode === 200) {
//use the access_token to retrieve something useful, for example
return auth_check(res.data.access_token);
}
}
});
 
var auth_check = function (token) {
var res = Meteor.http.call("GET", "http://api.glitch.com/simple/auth.check",
{params: {
oauth_token : token
}});
if (res.statusCode === 200) {
var json = JSON.parse(res.content);
//do something with the content here
}
};
Owner

Oauth example with Meteor. Using backbone for client-side routing as server-side routing is not currently available. Using Glitch Oauth as the provider in this example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.