-
Notifications
You must be signed in to change notification settings - Fork 0
/
strategy.js
44 lines (35 loc) · 1.36 KB
/
strategy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var OAuth2Strategy = require('passport-oauth2')
, util = require('util');
function Strategy(options, verify) {
options = options || {};
options.realm = options.realm || 'master';
options.authorizationURL = options.authorizationURL || `auth/realms/${options.realm}/protocol/openid-connect/auth`;
options.tokenURL = options.tokenURL || `auth/realms/${options.realm}/protocol/openid-connect/auth`;
options.clientID = options.clientID || 'account';
options.scopeSeparator = options.scopeSeparator || ',';
options.customHeaders = options.customHeaders || {};
if (!options.customHeaders['User-Agent']) {
options.customHeaders['User-Agent'] = options.userAgent || 'passport-keycloak';
}
OAuth2Strategy.call(this, options, verify);
this.name = 'keycloak';
this._userProfileURL = options.userProfileURL || `auth/realms/${options.realm}/protocol/openid-connect/userinfo`;
this._oauth2.useAuthorizationHeaderforGET(true);
}
util.inherits(Strategy, OAuth2Strategy);
Strategy.prototype.userProfile = function(accessToken, done) {
this._oauth2.get(this._userProfileURL, accessToken, function (err, body, _) {
var profile;
if (err) {
return done(err);
}
try {
profile = JSON.parse(body);
} catch (e) {
return done(e);
}
profile.provider = 'keycloak';
done(null, profile);
});
}
module.exports = Strategy;