Merge pull request #5275 from RocketChat/oauth-fixes

Oauth fixes
pull/5285/head
Gabriel Engel 9 years ago committed by GitHub
commit 12e6b61b19
  1. 3
      packages/rocketchat-custom-oauth/custom_oauth_client.js
  2. 9
      packages/rocketchat-custom-oauth/custom_oauth_server.js
  3. 1
      packages/rocketchat-i18n/i18n/en.i18n.json
  4. 1
      packages/rocketchat-lib/package.js
  5. 15
      packages/rocketchat-lib/server/methods/refreshOAuthService.js
  6. 8
      packages/rocketchat-ui-admin/admin/admin.coffee
  7. 1
      packages/rocketchat-ui-admin/admin/admin.html

@ -46,7 +46,6 @@ export class CustomOAuth {
}
configureLogin() {
self = this;
const loginWithService = 'loginWith' + s.capitalize(this.name);
Meteor[loginWithService] = (options, callback) => {
@ -57,7 +56,7 @@ export class CustomOAuth {
}
const credentialRequestCompleteCallback = Accounts.oauth.credentialRequestCompleteHandler(callback);
self.requestCredential(options, credentialRequestCompleteCallback);
this.requestCredential(options, credentialRequestCompleteCallback);
};
}

@ -224,14 +224,14 @@ export class CustomOAuth {
if (this.usernameField.indexOf('#{') > -1) {
username = this.usernameField.replace(/#{(.+?)}/g, function(match, field) {
if (!data[field]) {
throw new Meteor.Error(`Username template item "${field}" not found in data`, data);
throw new Meteor.Error('field_not_found', `Username template item "${field}" not found in data`, data);
}
return data[field];
});
} else {
username = data[this.usernameField];
if (!username) {
throw new Meteor.Error(`Username field "${this.usernameField}" not found in data`, data);
throw new Meteor.Error('field_not_found', `Username field "${this.usernameField}" not found in data`, data);
}
}
@ -252,6 +252,11 @@ export class CustomOAuth {
return;
}
// User already created or merged
if (user.services && user.services[serviceName] && user.services[serviceName].id === serviceData.id) {
return;
}
if (this.mergeUsers !== true) {
throw new Meteor.Error('CustomOAuth', `User with username ${user.username} already exists`);
}

@ -1064,6 +1064,7 @@
"Read_only_group": "Read Only Group",
"Record": "Record",
"Redirect_URI": "Redirect URI",
"Refresh_oauth_services": "Refresh OAuth Services",
"Refresh_keys": "Refresh keys",
"Refresh_your_page_after_install_to_enable_screen_sharing": "Refresh your page after install to enable screen sharing",
"Register": "Register a new account",

@ -115,6 +115,7 @@ Package.onUse(function(api) {
// SERVER METHODS
api.addFiles('server/methods/addOAuthService.coffee', 'server');
api.addFiles('server/methods/refreshOAuthService.js', 'server');
api.addFiles('server/methods/addUserToRoom.coffee', 'server');
api.addFiles('server/methods/archiveRoom.coffee', 'server');
api.addFiles('server/methods/checkRegistrationSecretURL.coffee', 'server');

@ -0,0 +1,15 @@
Meteor.methods({
refreshOAuthService() {
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'refreshOAuthService' });
}
if (RocketChat.authz.hasPermission(Meteor.userId(), 'add-oauth-service') !== true) {
throw new Meteor.Error('error-action-not-allowed', 'Refresh OAuth Services is not allowed', { method: 'refreshOAuthService', action: 'Refreshing_OAuth_Services' });
}
ServiceConfiguration.configurations.remove({});
RocketChat.models.Settings.update({_id: /^Accounts_OAuth_.+/}, {$set: {_updatedAt: new Date}}, {multi: true});
}
});

@ -321,6 +321,14 @@ Template.admin.events
if err
handleError(err)
"click .submit .refresh-oauth": (e, t) ->
toastr.info TAPi18n.__ 'Refreshing'
Meteor.call 'refreshOAuthService', (err) ->
if err
handleError(err)
else
toastr.success TAPi18n.__ 'Done'
"click .submit .remove-custom-oauth": (e, t) ->
name = this.section.replace('Custom OAuth: ', '')
config =

@ -208,6 +208,7 @@
<div class="submit">
{{#if $eq group._id 'OAuth'}}
<button class="button secondary refresh-oauth"><span>{{_ "Refresh_oauth_services"}}</span></button>
<button class="button secondary add-custom-oauth"><span>{{_ "Add_custom_oauth"}}</span></button>
{{/if}}
{{#if $eq group._id 'Assets'}}

Loading…
Cancel
Save