Skip to content

Commit

Permalink
[NEW] Guess a user's name from SAML credentials (#15240)
Browse files Browse the repository at this point in the history
* Determine a user's name from SAML username

* Determine name only if username exists
  • Loading branch information
mrsimpson authored and sampaiodiego committed Sep 19, 2019
1 parent f2bd39b commit 1db06a5
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/meteor-accounts-saml/server/saml_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ Accounts.normalizeUsername = function(name) {
return name;
};

const guessNameFromUsername = (username) =>
username
.replace(/\W/g, ' ')
.replace(/\s(.)/g, (u) => u.toUpperCase())
.replace(/^(.)/, (u) => u.toLowerCase())
.replace(/^\w/, (u) => u.toUpperCase());

Accounts.registerLoginHandler(function(loginRequest) {
if (!loginRequest.saml || !loginRequest.credentialToken) {
return undefined;
Expand Down Expand Up @@ -185,6 +192,7 @@ Accounts.registerLoginHandler(function(loginRequest) {

if (username) {
newUser.username = username;
newUser.name = newUser.name || guessNameFromUsername(username);
}

const userId = Accounts.insertUserDoc({}, newUser);
Expand Down

0 comments on commit 1db06a5

Please sign in to comment.