Fix custom auth (#15141)

pull/15148/head
Marcos Spessatto Defendi 6 years ago committed by Diego Sampaio
parent 47cf06d055
commit d1372d7ad1
No known key found for this signature in database
GPG Key ID: E060152B30502562
  1. 5
      app/custom-oauth/server/custom_oauth_server.js
  2. 3
      app/lib/server/oauth/facebook.js
  3. 2
      app/lib/server/oauth/google.js
  4. 3
      app/lib/server/oauth/twitter.js
  5. 10
      app/models/server/models/Users.js

@ -365,7 +365,7 @@ export class CustomOAuth {
}
if (serviceData.username) {
const user = Users.findOneByUsernameIgnoringCase(serviceData.username);
const user = Users.findOneByUsernameAndServiceNameIgnoringCase(serviceData.username, serviceName);
if (!user) {
return;
}
@ -430,10 +430,9 @@ export class CustomOAuth {
check(options, Match.ObjectIncluding({
accessToken: String,
expiresIn: Match.Integer,
identity: Match.Maybe(Object),
}));
const identity = options.identity || self.getIdentity(options.accessToken);
const identity = self.getIdentity(options.accessToken);
const serviceData = {
accessToken: options.accessToken,

@ -45,10 +45,9 @@ registerAccessTokenService('facebook', function(options) {
accessToken: String,
secret: String,
expiresIn: Match.Integer,
identity: Match.Maybe(Object),
}));
const identity = options.identity || getIdentity(options.accessToken, whitelisted, options.secret);
const identity = getIdentity(options.accessToken, whitelisted, options.secret);
const serviceData = {
accessToken: options.accessToken,

@ -35,7 +35,7 @@ registerAccessTokenService('google', function(options) {
identity: Match.Maybe(Object),
}));
const identity = options.identity || getIdentity(options.accessToken);
const identity = getIdentity(options.accessToken);
const serviceData = {
accessToken: options.accessToken,

@ -38,10 +38,9 @@ registerAccessTokenService('twitter', function(options) {
appId: String,
accessTokenSecret: String,
expiresIn: Match.Integer,
identity: Match.Maybe(Object),
}));
const identity = options.identity || getIdentity(options.accessToken, options.appId, options.appSecret, options.accessTokenSecret);
const identity = getIdentity(options.accessToken, options.appId, options.appSecret, options.accessTokenSecret);
const serviceData = {
accessToken: options.accessToken,

@ -376,6 +376,16 @@ export class Users extends Base {
return this.findOne(query, options);
}
findOneByUsernameAndServiceNameIgnoringCase(username, serviceName, options) {
if (typeof username === 'string') {
username = new RegExp(`^${ s.escapeRegExp(username) }$`, 'i');
}
const query = { username, [`services.${ serviceName }.id`]: serviceName };
return this.findOne(query, options);
}
findOneByUsername(username, options) {
const query = { username };

Loading…
Cancel
Save