Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a9ea2dace4 | |||
| aad18ad000 | |||
| b009965908 |
@@ -11,10 +11,11 @@ const bodyParser = require('body-parser')
|
||||
const favicon = require('serve-favicon')
|
||||
const cert = require('./cert')
|
||||
|
||||
let issuer = 'localhost:3333'
|
||||
let issuer = process.env.ISSUER || 'localhost:3333'
|
||||
let jwksOrigin = `https://${issuer}/`
|
||||
const audience = process.env.AUDIENCE || 'https://generic-audience'
|
||||
const adminCustomClaim = process.env.ADMIN_CUSTOM_CLAIM || 'https://unbound.se/admin'
|
||||
const emailCustomClaim = process.env.EMAIL_CUSTOM_CLAIM || 'https://unbound.se/email'
|
||||
|
||||
const debug = Debug('app')
|
||||
|
||||
@@ -27,6 +28,18 @@ const corsOpts = (req, cb) => {
|
||||
cb(null, { origin: req.headers.origin })
|
||||
}
|
||||
|
||||
const addCustomClaims = (email, customClaims, token) => {
|
||||
const emailClaim = {}
|
||||
emailClaim[emailCustomClaim] = email
|
||||
return [...customClaims, emailClaim].reduce((acc, claim) => {
|
||||
return {
|
||||
...acc,
|
||||
...claim
|
||||
}
|
||||
}, token)
|
||||
|
||||
}
|
||||
|
||||
// Configure our small auth0-mock-server
|
||||
app.options('*', cors(corsOpts))
|
||||
.use(cors())
|
||||
@@ -42,24 +55,19 @@ app.post('/oauth/token', (req, res) => {
|
||||
const session = sessions[code]
|
||||
|
||||
let date = Math.floor(Date.now() / 1000)
|
||||
let accessToken = jwt.sign(Buffer.from(JSON.stringify({
|
||||
let accessToken = jwt.sign(Buffer.from(JSON.stringify(addCustomClaims(session.email, session.customClaims, {
|
||||
iss: jwksOrigin,
|
||||
aud: [audience],
|
||||
sub: 'auth0|' + session.email,
|
||||
iat: date,
|
||||
exp: date + 7200,
|
||||
azp: session.clientId
|
||||
})), privateKey, {
|
||||
}))), privateKey, {
|
||||
algorithm: 'RS256',
|
||||
keyid: thumbprint
|
||||
})
|
||||
|
||||
const token = session.customClaims.reduce((acc, claim) => {
|
||||
return {
|
||||
...acc,
|
||||
...claim
|
||||
}
|
||||
}, {
|
||||
let idToken = jwt.sign(Buffer.from(JSON.stringify(addCustomClaims(session.email, session.customClaims, {
|
||||
iss: jwksOrigin,
|
||||
aud: session.clientId,
|
||||
nonce: session.nonce,
|
||||
@@ -69,8 +77,7 @@ app.post('/oauth/token', (req, res) => {
|
||||
azp: session.clientId,
|
||||
name: 'Example Person',
|
||||
picture: 'https://cdn.playbuzz.com/cdn/5458360f-32ea-460e-a707-1a2d26760558/70bda687-cb84-4756-8a44-8cf735ed87b3.jpg'
|
||||
})
|
||||
let idToken = jwt.sign(Buffer.from(JSON.stringify(token)), privateKey, {
|
||||
}))), privateKey, {
|
||||
algorithm: 'RS256',
|
||||
keyid: thumbprint
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user