Skip to content

Commit

Permalink
Merge pull request #9066 from pierreozoux/patch-1
Browse files Browse the repository at this point in the history
[NEW] Make Custom oauth accept nested usernameField
  • Loading branch information
rodrigok committed Dec 19, 2017
2 parents 9d58879 + f8e5a9a commit 838278a
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions packages/rocketchat-custom-oauth/server/custom_oauth_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 838278a

Please sign in to comment.