mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Add an option to configure scope for google and facebook login.
This commit is contained in:
@@ -5,11 +5,16 @@
|
||||
|
||||
var state = Meteor.uuid();
|
||||
// XXX I think there's a smaller popup. Replace with appropriate URL.
|
||||
// XXX need to support configuring scope
|
||||
|
||||
var scope = "email";
|
||||
if (Meteor.accounts.facebook._options &&
|
||||
Meteor.accounts.facebook._options.scope)
|
||||
scope = Meteor.accounts.facebook._options.scope.join(',');
|
||||
|
||||
var loginUrl =
|
||||
'https://www.facebook.com/dialog/oauth?client_id=' + Meteor.accounts.facebook._appId +
|
||||
'&redirect_uri=' + Meteor.accounts.facebook._appUrl + '/_oauth/facebook?close' +
|
||||
'&scope=email&state=' + state;
|
||||
'&scope=' + scope + '&state=' + state;
|
||||
|
||||
Meteor.accounts.oauth2.initiateLogin(state, loginUrl);
|
||||
};
|
||||
|
||||
@@ -2,9 +2,10 @@ if (!Meteor.accounts.facebook) {
|
||||
Meteor.accounts.facebook = {};
|
||||
}
|
||||
|
||||
Meteor.accounts.facebook.config = function(appId, appUrl) {
|
||||
Meteor.accounts.facebook.config = function(appId, appUrl, options) {
|
||||
Meteor.accounts.facebook._appId = appId;
|
||||
Meteor.accounts.facebook._appUrl = appUrl;
|
||||
Meteor.accounts.facebook._options = options;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -4,12 +4,24 @@
|
||||
throw new Meteor.accounts.ConfigError("Need to call Meteor.accounts.google.config first");
|
||||
|
||||
var state = Meteor.uuid();
|
||||
// XXX need to support configuring access_type and scope
|
||||
|
||||
// always need this to get user id from google.
|
||||
var required_scope = ['https://www.googleapis.com/auth/userinfo.profile'];
|
||||
var scope = ['https://www.googleapis.com/auth/userinfo.email'];
|
||||
if (Meteor.accounts.google._options &&
|
||||
Meteor.accounts.google._options.scope)
|
||||
scope = Meteor.accounts.google._options.scope;
|
||||
scope = _.union(scope, required_scope);
|
||||
var flat_scope = _.map(scope, encodeURIComponent).join('+');
|
||||
|
||||
// Might be good to have a way to set access_type=offline. Need to
|
||||
// both set it here and store the refresh token on the server.
|
||||
|
||||
var loginUrl =
|
||||
'https://accounts.google.com/o/oauth2/auth' +
|
||||
'?response_type=code' +
|
||||
'&client_id=' + Meteor.accounts.google._clientId +
|
||||
'&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile' +
|
||||
'&scope=' + flat_scope +
|
||||
'&redirect_uri=' + Meteor.accounts.google._appUrl + '/_oauth/google?close' +
|
||||
'&state=' + state;
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@ if (!Meteor.accounts.google) {
|
||||
Meteor.accounts.google = {};
|
||||
}
|
||||
|
||||
Meteor.accounts.google.config = function(clientId, appUrl) {
|
||||
Meteor.accounts.google.config = function(clientId, appUrl, options) {
|
||||
Meteor.accounts.google._clientId = clientId;
|
||||
Meteor.accounts.google._appUrl = appUrl;
|
||||
Meteor.accounts.google._options = options;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user