diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3f7f215..7b9929f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,7 +3,6 @@ include: stages: - build -- acctest variables: DOCKER_HOST: tcp://docker:2376 @@ -21,16 +20,3 @@ build: script: - build - push - artifacts: - paths: - - k8s - -acceptance-test: - stage: acctest - variables: - AUTH0MOCK_COMMIT: ${CI_COMMIT_SHA} - AUTH0MOCK_PIPELINE: ${CI_PIPELINE_ID} - TRIGGERED_BY: registry.gitlab.com/unboundsoftware/shiny/auth0mock - trigger: - project: unboundsoftware/shiny/acctest - strategy: depend diff --git a/app.js b/app.js index 152427e..37460f5 100644 --- a/app.js +++ b/app.js @@ -1,23 +1,23 @@ -process.env.DEBUG = 'app*'; +process.env.DEBUG = 'app*' -const express = require('express'); +const express = require('express') const cookieParser = require('cookie-parser') -const app = express(); -const jwt = require('jsonwebtoken'); -const Debug = require('debug'); -const path = require('path'); -const cors = require('cors'); -const bodyParser = require('body-parser'); -const favicon = require('serve-favicon'); -const cert = require('./cert'); +const app = express() +const jwt = require('jsonwebtoken') +const Debug = require('debug') +const path = require('path') +const cors = require('cors') +const bodyParser = require('body-parser') +const favicon = require('serve-favicon') +const cert = require('./cert') -let issuer = 'localhost:3333'; -let jwksOrigin = `https://${issuer}/`; -const audience = process.env.AUDIENCE || 'https://generic-audience'; +let issuer = 'localhost:3333' +let jwksOrigin = `https://${issuer}/` +const audience = process.env.AUDIENCE || 'https://generic-audience' -const debug = Debug('app'); +const debug = Debug('app') -let { privateKey, certDer, thumbprint, exponent, modulus } = cert(jwksOrigin); +let { privateKey, certDer, thumbprint, exponent, modulus } = cert(jwksOrigin) const sessions = {} const challenges = {} @@ -33,25 +33,25 @@ app.options('*', cors(corsOpts)) .use(bodyParser.urlencoded({ extended: true })) .use(cookieParser()) .use(express.static(`${__dirname}/public`)) - .use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); + .use(favicon(path.join(__dirname, 'public', 'favicon.ico'))) // This route can be used to generate a valid jwt-token. app.post('/oauth/token', (req, res) => { const code = req.body.code const session = sessions[code] - let date = Math.floor(Date.now() / 1000); + let date = Math.floor(Date.now() / 1000) let accessToken = jwt.sign(Buffer.from(JSON.stringify({ iss: jwksOrigin, aud: [audience], sub: 'auth0|' + session.email, iat: date, exp: date + 7200, - azp: session.clientId, + azp: session.clientId })), privateKey, { algorithm: 'RS256', keyid: thumbprint - }); + }) let idToken = jwt.sign(Buffer.from(JSON.stringify({ iss: jwksOrigin, @@ -67,9 +67,9 @@ app.post('/oauth/token', (req, res) => { })), privateKey, { algorithm: 'RS256', keyid: thumbprint - }); + }) - debug('Signed token for ' + session.email); + debug('Signed token for ' + session.email) // res.json({ token }); res.json({ @@ -79,25 +79,25 @@ app.post('/oauth/token', (req, res) => { expires_in: 7200, token_type: 'Bearer' }) -}); +}) // This route can be used to generate a valid jwt-token. app.get('/token/:email', (req, res) => { if (!req.params.email) { - debug('No user was given!'); - return res.status(400).send('user is missing'); + debug('No user was given!') + return res.status(400).send('user is missing') } const token = jwt.sign({ - user_id: 'auth0|' + req.params.email, - }, privateKey); - debug('Signed token for ' + req.params.email); - res.json({ token }); -}); + user_id: 'auth0|' + req.params.email + }, privateKey) + debug('Signed token for ' + req.params.email) + res.json({ token }) +}) app.post('/code', (req, res) => { if (!req.body.email || !req.body.password || !req.body.codeChallenge) { - debug('Body is invalid!', req.body); - return res.status(400).send('Email or password is missing!'); + debug('Body is invalid!', req.body) + return res.status(400).send('Email or password is missing!') } const code = req.body.codeChallenge @@ -120,13 +120,13 @@ app.post('/code', (req, res) => { }) app.get('/authorize', (req, res) => { - const redirect = req.query.redirect_uri; - const state = req.query.state; - const nonce = req.query.nonce; - const clientId = req.query.client_id; - const codeChallenge = req.query.code_challenge; - const prompt = req.query.prompt; - const responseMode = req.query.response_mode; + const redirect = req.query.redirect_uri + const state = req.query.state + const nonce = req.query.nonce + const clientId = req.query.client_id + const codeChallenge = req.query.code_challenge + const prompt = req.query.prompt + const responseMode = req.query.response_mode if (prompt === 'none' && responseMode === 'web_message') { const code = req.cookies['auth0'] const session = sessions[code] @@ -158,39 +158,39 @@ app.get('/authorize', (req, res) => { httpOnly: true }) res.send(` - + - - + + Auth - + -
-
-
-
-
Login
-
- - +
+ +
+
+
Login
+
+ +
-
- - +
+ +
-
- -
@@ -199,11 +199,11 @@ app.get('/authorize', (req, res) => { `) } -}); +}) app.get('/userinfo', (req, res) => { res.contentType('application/json').send(JSON.stringify({ picture: 'https://cdn.playbuzz.com/cdn/5458360f-32ea-460e-a707-1a2d26760558/70bda687-cb84-4756-8a44-8cf735ed87b3.jpg' })) -}); +}) app.get('/v2/logout', (req, res) => { res.redirect(`${req.query.returnTo}?domain=${issuer}`) @@ -223,46 +223,46 @@ app.get('/.well-known/jwks.json', (req, res) => { n: modulus, use: 'sig', x5c: [certDer], - x5t: thumbprint, - }, - ], - })); -}); + x5t: thumbprint + } + ] + })) +}) // This route returns the inside of a jwt-token. Your main application // should use this route to keep the auth0-flow app.post('/tokeninfo', (req, res) => { if (!req.body.id_token) { - debug('No token given in the body!'); - return res.status(401).send('missing id_token'); + debug('No token given in the body!') + return res.status(401).send('missing id_token') } - const data = jwt.decode(req.body.id_token); + const data = jwt.decode(req.body.id_token) if (data) { - debug('Return token data from ' + data.user_id); - res.json(data); + debug('Return token data from ' + data.user_id) + res.json(data) } else { - debug('The token was invalid and could not be decoded!'); - res.status(401).send('invalid id_token'); + debug('The token was invalid and could not be decoded!') + res.status(401).send('invalid id_token') } -}); +}) app.post('/issuer', (req, res) => { if (!req.body.issuer) { - debug('No issuer given in the body!'); - return res.status(401).send('missing issuer'); + debug('No issuer given in the body!') + return res.status(401).send('missing issuer') } - issuer = req.body.issuer; - jwksOrigin = `https://${issuer}/`; - const { privateKey: key, certDer: der, thumbPrint: thumb, exponent: exp, modulus: mod } = cert(jwksOrigin); - privateKey = key; - certDer = der; - thumbprint = thumb; - exponent = exp; - modulus = mod; - debug('Issuer set to ' + req.body.issuer); + issuer = req.body.issuer + jwksOrigin = `https://${issuer}/` + const { privateKey: key, certDer: der, thumbPrint: thumb, exponent: exp, modulus: mod } = cert(jwksOrigin) + privateKey = key + certDer = der + thumbprint = thumb + exponent = exp + modulus = mod + debug('Issuer set to ' + req.body.issuer) res.send('ok') -}); +}) app.listen(3333, () => { - debug('Auth0-Mock-Server listening on port 3333!'); -}); + debug('Auth0-Mock-Server listening on port 3333!') +})