-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (50 loc) · 1.43 KB
/
index.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* define dependencies
- author : Prabir Ghosh
- mail : mymail.prabir@gmail.com
- website : https://twogp.com
*/
const saml = require('saml-encoder-decoder-js')
const saml20 = require('saml20')
const tokenizer = require('./src/tokenizer')
module.exports = {
client: function (options) {
CAClient = {}
CAClient.jwt = new tokenizer.create(options.jwt, options.key)
CAClient.options = options.ca
/*
Method login ()
- response: CA SiteMinder Response
- next: callback returns jwt token
*/
CAClient.login = function (response, next) {
const options = CAClient.options
saml.decodeSamlPost(decodeURIComponent(response), function (err, data) {
if (err) {
next(err)
}
saml20.validate(data, CAClient.options, function (err, profile) {
if (err) {
next(err)
} else {
const token = encodeURI(CAClient.jwt.jwtSign(profile))
next(token)
}
})
})
},
/*
Method validate ()
- token: request from the origin url
- returns claims on success
*/
CAClient.validate = function (token) {
try {
const claims = CAClient.jwt.jwtVerify(decodeURI(token))
return claims
} catch (err) {
return err
}
}
return CAClient
}
}