Make Custom oauth accept nested usernameField

pull/9066/head
Pierre Ozoux 8 years ago committed by GitHub
parent 4d46831543
commit 108839c855
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      packages/rocketchat-custom-oauth/server/custom_oauth_server.js

@ -260,20 +260,12 @@ export class CustomOAuth {
getUsername(data) {
let username = '';
if (this.usernameField.indexOf('#{') > -1) {
username = this.usernameField.replace(/#{(.+?)}/g, function(match, field) {
if (!data[field]) {
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('field_not_found', `Username field "${ this.usernameField }" not found in data`, data);
}
username = this.usernameField.split('.').reduce(function(prev, curr) {
return prev ? prev[curr] : undefined
}, data)
if (!username) {
throw new Meteor.Error('field_not_found', `Username field "${ this.usernameField }" not found in data`, data);
}
return username;
}

Loading…
Cancel
Save