Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d940a04d05 | |||
| 192929229f | |||
| 397d60361e | |||
| bb8deb221e | |||
| a465ae543a | |||
| 8aad0d6308 | |||
| 0166537d2f | |||
| 9f6e63ea50 | |||
| a30cb4b08c | |||
| abbc55ea6e | |||
| 779d78cdc6 |
+2
-2
@@ -1,4 +1,4 @@
|
||||
FROM node:18
|
||||
FROM node:20
|
||||
ENV AUDIENCE "https://shiny.unbound.se"
|
||||
ENV ORIGIN_HOST "auth0mock"
|
||||
ENV ORIGIN "https://auth0mock:3333"
|
||||
@@ -6,7 +6,7 @@ EXPOSE 3333
|
||||
WORKDIR /app
|
||||
ADD package.json yarn.lock /app/
|
||||
RUN yarn install --frozen-lockfile
|
||||
ADD app.js cert.js /app/
|
||||
ADD *.js /app/
|
||||
ADD public /app/public
|
||||
RUN mkdir -p /root/.config
|
||||
ENTRYPOINT yarn start
|
||||
|
||||
@@ -22,6 +22,22 @@ After you have installed all dependencies you can now run the app.
|
||||
Run `npm start` to start a local server.
|
||||
The port will be displayed to you as `http://0.0.0.0:3333` (or if you prefer IPv6, if you're using `express` server, then it's `http://[::1]:3333/`).
|
||||
|
||||
## Initial users
|
||||
|
||||
Adding a JSON file with the following layout will populate the users store when starting:
|
||||
|
||||
```json
|
||||
{
|
||||
"email@test.com": {
|
||||
"given_name": "name",
|
||||
"family_name": "family",
|
||||
"user_id": "id"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
By default `./users.json` will be read but this can be overridden by setting the environment variable `USERS_FILE`.
|
||||
|
||||
## API Documentation
|
||||
|
||||
### `GET` /token/:username
|
||||
|
||||
@@ -10,6 +10,7 @@ const cors = require('cors')
|
||||
const bodyParser = require('body-parser')
|
||||
const favicon = require('serve-favicon')
|
||||
const cert = require('./cert')
|
||||
const initialUsers = require('./users')
|
||||
|
||||
let issuer = process.env.ISSUER || 'localhost:3333'
|
||||
let jwksOrigin = `https://${issuer}/`
|
||||
@@ -22,7 +23,7 @@ const emailCustomClaim =
|
||||
const debug = Debug('app')
|
||||
|
||||
let { privateKey, certDer, thumbprint, exponent, modulus } = cert(jwksOrigin)
|
||||
|
||||
const users = initialUsers(process.env.USERS_FILE || './users.json')
|
||||
const sessions = {}
|
||||
const challenges = {}
|
||||
|
||||
@@ -114,6 +115,9 @@ app.post('/oauth/token', (req, res) => {
|
||||
exp: date + 7200,
|
||||
azp: session.clientId,
|
||||
name: 'Example Person',
|
||||
given_name: 'Example',
|
||||
family_name: 'Person',
|
||||
email: session.email,
|
||||
picture:
|
||||
'https://cdn.playbuzz.com/cdn/5458360f-32ea-460e-a707-1a2d26760558/70bda687-cb84-4756-8a44-8cf735ed87b3.jpg'
|
||||
})
|
||||
@@ -282,7 +286,12 @@ app.get('/userinfo', (req, res) => {
|
||||
})
|
||||
|
||||
app.get('/v2/logout', (req, res) => {
|
||||
res.redirect(`${req.query.returnTo}?domain=${issuer}`)
|
||||
const code = req.cookies['auth0']
|
||||
const session = sessions[code]
|
||||
if (session) {
|
||||
delete sessions[code]
|
||||
}
|
||||
res.redirect(req.query.returnTo)
|
||||
})
|
||||
|
||||
app.get('/.well-known/jwks.json', (req, res) => {
|
||||
@@ -346,11 +355,24 @@ app.post('/issuer', (req, res) => {
|
||||
})
|
||||
|
||||
app.get('/api/v2/users-by-email', (req, res) => {
|
||||
res.json([])
|
||||
const email = req.query.email
|
||||
console.log('users', users)
|
||||
const user = users[email]
|
||||
if (user === undefined) {
|
||||
res.json([])
|
||||
} else {
|
||||
res.json([user])
|
||||
}
|
||||
})
|
||||
|
||||
app.post('/api/v2/users', (req, res) => {
|
||||
const email = req.body.email
|
||||
users[email] = {
|
||||
email: email,
|
||||
given_name: 'Given',
|
||||
family_name: 'Last',
|
||||
user_id: email
|
||||
}
|
||||
res.json({
|
||||
user_id: `auth0|${email}`
|
||||
})
|
||||
|
||||
+2
-2
@@ -25,10 +25,10 @@
|
||||
"jsonwebtoken": "^9.0.0",
|
||||
"node-forge": "^1.3.1",
|
||||
"node-rsa": "^1.1.1",
|
||||
"nodemon": "^2.0.21",
|
||||
"nodemon": "^2.0.22",
|
||||
"serve-favicon": "^2.4.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"prettier": "^2.8.4"
|
||||
"prettier": "^2.8.8"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
const fs = require('fs')
|
||||
|
||||
const setup = (usersFile) => {
|
||||
let users = {}
|
||||
if (fs.existsSync(usersFile)) {
|
||||
console.log(`initial users file "${usersFile}" exists, reading`)
|
||||
const read = fs.readFileSync(usersFile, { encoding: 'utf8', flag: 'r' })
|
||||
users = JSON.parse(read)
|
||||
for (let key of Object.keys(users)) {
|
||||
users[key] = { ...users[key], email: key }
|
||||
}
|
||||
console.log('users:', users)
|
||||
} else {
|
||||
console.log(`initial users file "${usersFile}" missing`)
|
||||
}
|
||||
return users
|
||||
}
|
||||
module.exports = setup
|
||||
@@ -639,10 +639,10 @@ node-rsa@^1.1.1:
|
||||
dependencies:
|
||||
asn1 "^0.2.4"
|
||||
|
||||
nodemon@^2.0.21:
|
||||
version "2.0.21"
|
||||
resolved "https://registry.yarnpkg.com/nodemon/-/nodemon-2.0.21.tgz#267edff25578da91075d6aa54346ef77ecb7b302"
|
||||
integrity sha512-djN/n2549DUtY33S7o1djRCd7dEm0kBnj9c7S9XVXqRUbuggN1MZH/Nqa+5RFQr63Fbefq37nFXAE9VU86yL1A==
|
||||
nodemon@^2.0.22:
|
||||
version "2.0.22"
|
||||
resolved "https://registry.yarnpkg.com/nodemon/-/nodemon-2.0.22.tgz#182c45c3a78da486f673d6c1702e00728daf5258"
|
||||
integrity sha512-B8YqaKMmyuCO7BowF1Z1/mkPqLk6cs/l63Ojtd6otKjMx47Dq1utxfRxcavH1I7VSaL8n5BUaoutadnsX3AAVQ==
|
||||
dependencies:
|
||||
chokidar "^3.5.2"
|
||||
debug "^3.2.7"
|
||||
@@ -714,10 +714,10 @@ picomatch@^2.2.1:
|
||||
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.0.tgz#f1f061de8f6a4bf022892e2d128234fb98302972"
|
||||
integrity sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==
|
||||
|
||||
prettier@^2.8.4:
|
||||
version "2.8.4"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.4.tgz#34dd2595629bfbb79d344ac4a91ff948694463c3"
|
||||
integrity sha512-vIS4Rlc2FNh0BySk3Wkd6xmwxB0FpOndW5fisM5H8hsZSxU2VWVB5CWIkIjWvrHjIhxk2g3bfMKM87zNTrZddw==
|
||||
prettier@^2.8.8:
|
||||
version "2.8.8"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
|
||||
integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==
|
||||
|
||||
process-nextick-args@~2.0.0:
|
||||
version "2.0.0"
|
||||
|
||||
Reference in New Issue
Block a user