Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d940a04d05 | |||
| 192929229f |
+1
-1
@@ -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,8 +23,7 @@ const emailCustomClaim =
|
||||
const debug = Debug('app')
|
||||
|
||||
let { privateKey, certDer, thumbprint, exponent, modulus } = cert(jwksOrigin)
|
||||
|
||||
const users = {}
|
||||
const users = initialUsers(process.env.USERS_FILE || './users.json')
|
||||
const sessions = {}
|
||||
const challenges = {}
|
||||
|
||||
@@ -356,24 +356,22 @@ app.post('/issuer', (req, res) => {
|
||||
|
||||
app.get('/api/v2/users-by-email', (req, res) => {
|
||||
const email = req.query.email
|
||||
|
||||
console.log('users', users)
|
||||
const user = users[email]
|
||||
if (user === undefined) {
|
||||
res.json([{}])
|
||||
res.json([])
|
||||
} else {
|
||||
res.json([
|
||||
user
|
||||
])
|
||||
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,
|
||||
email: email,
|
||||
given_name: 'Given',
|
||||
family_name: 'Last',
|
||||
user_id: email
|
||||
}
|
||||
res.json({
|
||||
user_id: `auth0|${email}`
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user