OAuth made easy for 90 providers
Presented by Thibaud and Mehdi - Co founders
OAuth.popup('facebook', callback)
OAuth.popup('twitter', callback)
OAuth.popup('github', callback)
...
Create an app on facebook
Set your API Key on OAuth.io
Add oauth.js in your header (html)
then
OAuth.popup('facebook', function(err, res) {
//todo with res.access_token
});
git clone git://github.com/oauth-io/oauthd.git
Global dependancies
npm install -g coffee-script grunt grunt-cli forever
OAuth.io dependanciesnpm install
npm start
Authentication, save informations in database ...
Exchange the code against an access_token in your backend
Works with all backend langage
var csrf_token = secu.generateHash()
req.session.csrf_tokens = req.session.csrf_tokens || []
req.session.csrf_tokens.push(csrf_token)
if (req.session.csrf_tokens.length > 4)
req.session.csrf_tokens.shift() // keep 4 tokens max
return csrf_token
OAuth.initialize('MpnCNnhVAq_zL089ua883AevC1o')
OAuth.popup(provider, {
"state": $scope.csrfToken
}, function(error, success) {
if (error) {
alert("error")
return
}
UserService.signin(success.code, provider, function(data) {
console.log(data)
$location.path('/account')
}, function(error) {
alert('error:' + error)
})
})
request.post({ url: 'https://oauth.io/auth/access_token', form: { code: req.body.code, key: "YOUR_OAUTHIO_PUBLIC_KEY", secret: "YOUR_OAUTHIO_SECRET_KEY" } }, function (e,r,body) { var data = JSON.parse(body), check = secu.check(req, data.state) if (check.error) { return res.json(check) } callback(data) });
The access_token is send to callback()
if OAuth2
request.get({
url: this.data[provider].url,
headers: {
access_token: data.access_token
},
}, function(e, r, body) {
if (body)
callback(JSON.parse(body))
})
})
if OAuth1
request.get({
url: this.data[provider].url,
oauth: {
consumer_key: "XXXXXX",
consumer_secret: "YYYYYY",perm_token: data.oauth_token
secret_token: data.oauth_token_secret
}
}, function(e, r, body) {
if (body)
callback(JSON.parse(body))
})
Android & IOS
+ Request tools
OAuth.popup('facebook', function(err, res) {
res.get('/me', function(data) {
//todo with data
});
});
}
error: false,
message: "Thank you"
}