mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 16:23:28 +02:00
Add an OAuth2 auth provider.
This commit is contained in:
32
lib/units/auth/oauth2/strategy.js
Normal file
32
lib/units/auth/oauth2/strategy.js
Normal file
@@ -0,0 +1,32 @@
|
||||
var util = require('util')
|
||||
|
||||
var oauth2 = require('passport-oauth2')
|
||||
|
||||
function Strategy(options, verify) {
|
||||
oauth2.Strategy.call(this, options, verify)
|
||||
if (!options.authorizationURL) {
|
||||
throw new TypeError('OAuth2Strategy requires a userinfoURL option')
|
||||
}
|
||||
this._userinfoURL = options.userinfoURL
|
||||
this._oauth2.useAuthorizationHeaderforGET(true)
|
||||
}
|
||||
|
||||
util.inherits(Strategy, oauth2.Strategy)
|
||||
|
||||
Strategy.prototype.userProfile = function(accessToken, callback) {
|
||||
this._oauth2.get(this._userinfoURL, accessToken, function(err, data) {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
}
|
||||
else {
|
||||
try {
|
||||
return callback(null, JSON.parse(data))
|
||||
}
|
||||
catch (err) {
|
||||
return callback(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = Strategy
|
||||
Reference in New Issue
Block a user