Repository navigation
Description
Rocket.Chat Version: 0.56.0-develop
Running Instances: 1
DB Replicaset OpLog: Enabled
Node Version: v4.8.1
In the continuity of my issue #5842 (and the PR #6028), I would like to be able to specify custom roles per-services. I would need to tell that "every users coming from Github should have the github role", and "every users coming from our custom OAuth system (keycloak-like) should have the staff role".
I'm managing to write some code in order to achieve what I would like (and it works pretty great). But I would like your opinion. Let's say I'm defining that :
- every users logging in with Github has the 'github' role
- every users logging in with Google has the 'google' role
- every users logging in with Keycloack has the 'staff' role
Now, let's say a user (named Foo Bar), create an account with keycloack. He obtains the 'staff' role. Now he decides to login with his Github account (where he uses the same email address has the company one).
Which roles it will have ? 'staff' ? 'github' ? both of them ?
For now, I have to two pieces of code achieving this (I dint't check for syntax/eslint for now) :
// It assigns any roles given by my keycloak server to users authenticating through my keycloak server
// In Accounts.validateNewUser in custom_oauth_server.js
// I have my keycloack server doing a mapping, sending a parameter "roles = 'staff'". Hence the "user.services[service].roles"
let roles = [];
for (var service in user.services) {
roles = roles.concat(String(user.services[service].roles).split(',').map(s => s.trim()))
}
roles = roles.filter(function(item, pos) {
return roles.indexOf(item) == pos;
});
user.roles = roles;and
// In Accounts.insertUserDoc in account.js
// I defined Accounts_OAuth_(GitHub|Linkedin|Google)_Roles settings in order to dynamically define the role in the Admin UI
RocketChat.settings.get(/^Accounts_OAuth_.+_Roles/, function(key, serviceRoles) {
if (serviceRoles.length > 0) {
roles = roles.concat(String(serviceRoles).split(',').map(s => s.trim()));
}
});
roles = roles.filter(function(item, pos) {
return roles.indexOf(item) == pos;
});Thanks
Activity
marceloschmidt commentedon May 5, 2017
IMHO user should have both roles. @rodrigok what do you think?
engelgabriel commentedon Jun 12, 2018
The documentation about Keycloak is going to be written. Please follow https://github.com/RocketChat/docs/issues/790 and fell free to help us :)