-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
49 lines (39 loc) · 1.63 KB
/
app.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
const md5 = require('md5');
const express = require('express')
const app = express()
const port = 8080
const endpoint = 'https://example.widencollective.com/auth/simple'
const sharedSecret = Math.random().toString(36).substring(2, 15)
app.get('/', function (req, res) { res.render('app') })
app.get('/post', function (req, res) { res.render('post', { endpoint, ...userFields() }) })
app.get('/get', function (req, res) {
const queryParams = Object.entries(userFields()).map(([key, value]) => `${key}=${value}`).join('&')
res.render('get', {
endpointWithParams: `${endpoint}?${queryParams}`
})
})
app.set('view engine', 'pug')
app.listen(port, () => console.log(`Widen Simple One-Way SSO Node.js Example app listening on port ${port}!`))
const userFields = () => {
let fields = {
timestamp: new Date().toUTCString(),
guid: '123456789',
email: '[email protected]',
first_name: 'Example',
last_name: 'User',
roles: 'General Role'
}
console.log(`fields = ${JSON.stringify(fields)}`)
// Calculating the signature...
// First join all the field values without a delimiter (in ascending order by key)
let fieldString = Object.keys(fields).sort().map(k => fields[k]).join('')
console.log(`fieldString = ${fieldString}`)
// Append the shared secret to the joined field String
let fieldStringWithSharedSecret = fieldString + sharedSecret
console.log(`fieldStringWithSharedSecret = ${fieldStringWithSharedSecret}`)
// Calculate md5 hash of the field String with shared secret
let signature = md5(fieldStringWithSharedSecret)
console.log(`signature = ${signature}`)
fields.signature = signature
return fields
}