Skip to content

Commit aa36e5d

Browse files
committed
Automap roles and mobile from saml login
1 parent fba5cb6 commit aa36e5d

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

OpenFlow/src/LoginProvider.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,33 @@ export class LoginProvider {
413413
_user.name = profile["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"];
414414
}
415415
_user.username = username;
416-
(_user as any).mobile = profile.mobile;
416+
if (!Util.IsNullEmpty(profile["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/mobile"])) {
417+
(_user as any).mobile = profile["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/mobile"];
418+
}
417419
if (Util.IsNullEmpty(_user.name)) { done("Cannot add new user, name is empty, please add displayname to claims", null); return; }
418420
// _user = await Config.db.InsertOne(_user, "users", 0, false, TokenUser.rootToken());
419421
var jwt: string = TokenUser.rootToken();
420422
_user = await User.ensureUser(jwt, _user.name, _user.username, null, null);
421423
}
424+
} else {
425+
if (!Util.IsNullUndefinded(_user)) {
426+
if (!Util.IsNullEmpty(profile["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/mobile"])) {
427+
(_user as any).mobile = profile["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/mobile"];
428+
}
429+
await _user.Save(jwt);
430+
}
431+
}
432+
433+
if (!Util.IsNullUndefinded(_user)) {
434+
if (!Util.IsNullEmpty(profile["http://schemas.xmlsoap.org/claims/Group"])) {
435+
var strroles: string[] = profile["http://schemas.xmlsoap.org/claims/Group"];
436+
for (var i = 0; i < strroles.length; i++) {
437+
var role: Role = await Role.FindByNameOrId(strroles[i], jwt);
438+
role.AddMember(_user);
439+
await role.Save(jwt);
440+
}
441+
await _user.DecorateWithRoles();
442+
}
422443
}
423444

424445
if (Util.IsNullUndefinded(_user)) {

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.332
1+
0.0.333

0 commit comments

Comments
 (0)