Add configurable profileURL parameter and missing profile details
This commit is contained in:
Родитель
64ec2cb7d2
Коммит
7351d20bda
|
@ -1,5 +1,6 @@
|
|||
var OAuth2Strategy = require('passport-oauth2'),
|
||||
util = require('util'),
|
||||
uri = require('url'),
|
||||
InternalOAuthError = require('passport-oauth2').InternalOAuthError;
|
||||
|
||||
/**
|
||||
|
@ -21,6 +22,7 @@ function Strategy(options, verify) {
|
|||
|
||||
OAuth2Strategy.call(this, options, verify);
|
||||
this.name = "webmaker";
|
||||
this._profileUrl = options.profileURL || "https://id.webmaker.org/user";
|
||||
}
|
||||
|
||||
util.inherits(Strategy, OAuth2Strategy);
|
||||
|
@ -38,6 +40,7 @@ Strategy.prototype.authorizationParams = function(options) {
|
|||
}
|
||||
|
||||
// This is just to get around a temporary bug of Webmaker calling "scope" as "scopes" and therefore rejecting "scope".
|
||||
//TODO: Properly deal with multi-scope scenarios, currently an error is thrown.
|
||||
if (options.scope) {
|
||||
params['scopes'] = options.scope;
|
||||
options.scope = null;
|
||||
|
@ -56,12 +59,11 @@ Strategy.prototype.authorizationParams = function(options) {
|
|||
* @param done
|
||||
*/
|
||||
Strategy.prototype.userProfile = function(accessToken, done) {
|
||||
var profileEndPoint = 'https://id.webmaker.org/user';
|
||||
var url = uri.parse(this._profileUrl);
|
||||
|
||||
this._oauth2.useAuthorizationHeaderforGET(true);
|
||||
this._oauth2.setAuthMethod("token");
|
||||
this._oauth2.get(profileEndPoint, accessToken, function (err, body, res) {
|
||||
|
||||
this._oauth2.get(url, accessToken, function (err, body, res) {
|
||||
if (err) {
|
||||
return done(new InternalOAuthError('Failed to fetch user profile', err));
|
||||
}
|
||||
|
@ -70,9 +72,9 @@ Strategy.prototype.userProfile = function(accessToken, done) {
|
|||
var json = JSON.parse(body);
|
||||
var profile = { provider: 'webmaker' };
|
||||
|
||||
//TODO: Some fields are missing.
|
||||
profile.id = json.id;
|
||||
profile.displayName = json.username;
|
||||
profile.locale = json.prefLocale;
|
||||
profile.emails = [{ value: json.email }];
|
||||
profile.photos = [{ value: json.avatar }];
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче