Skip to content

Commit ca89a1e

Browse files
committed
Allow configuration of username and email scope and claim
1 parent 6dcefe3 commit ca89a1e

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ module.exports = {
7777
url: 'https://<keycloakserver/realms/<realm>',
7878
client_id: "cryptpad",
7979
client_secret: "<clientsecret>",
80-
jwt_alg: 'RS256'
80+
jwt_alg: 'RS256',
81+
username_scope: 'profile', (optional)
82+
username_claim: 'name', (optional)
8183
},
8284
/*
8385

protocols/oidc.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ module.exports = (SSOUtils) => {
3131
auth: (Env, cfg, cb) => {
3232
getClient(cfg, (err, client) => {
3333
if (err) { return void cb ('E_OIDC_CONNECT'); }
34+
let username_scope = cfg.username_scope || 'profile';
35+
let email_scope = cfg.email_scope || 'email'; // This is not yet used
3436

3537
const generators = OID.generators;
3638
const code_verifier = generators.codeVerifier();
3739
const code_challenge = generators.codeChallenge(code_verifier);
3840
const url = client.authorizationUrl({
39-
scope: 'openid email profile',
41+
scope: `openid ${username_scope} ${email_scope}`,
4042
resource: opts.callbackURL,
4143
access_type: 'offline',
4244
code_challenge,
@@ -52,11 +54,15 @@ module.exports = (SSOUtils) => {
5254

5355
const params = client.callbackParams(url);
5456
delete params.state;
57+
58+
let username_claim = cfg.username_claim || 'name';
59+
let email_claim = cfg.email_claim || 'email'; // This is not yet used
60+
5561
client.callback(opts.callbackURL, params, { code_verifier: token })
5662
.then((tokenSet) => {
5763
let j = tokenSet;
5864
let c = tokenSet.claims();
59-
let name = c.name;
65+
let name = c[username_claim];
6066
const end = () => {
6167
cb(void 0, {
6268
id: c.sub,

0 commit comments

Comments
 (0)