Skip to content

Commit 31f0580

Browse files
committed
update docs and point to example
1 parent 20a2fa8 commit 31f0580

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

README.md

+29-26
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,35 @@ An Express middleware to route login requests to an external authentication serv
88

99
## Usage
1010

11-
```
11+
```javascript
12+
const isProduction = process.env.NODE_ENV === 'production';
13+
const apiPortDefault = isProduction ? 443 : 3000;
14+
const apiPort = process.env.API_PORT || apiPortDefault;
15+
16+
const authConfig = {
17+
api: {
18+
endpoint: '/v1',
19+
host: process.env.API_HOST || 'http://localhost',
20+
port: process.env.API_PORT || apiPortDefault
21+
},
22+
auth: {
23+
clientId: isProduction ? process.env.JWT_CLIENT_ID : undefined,
24+
clientSecret: isProduction ? process.env.JWT_CLIENT_SECRET : undefined,
25+
endpoint: `${process.env.AUTHENTICATION_HOST}/authenticate`
26+
},
27+
debug: !isProduction,
28+
endpoint: '/api',
29+
sessionStore: {
30+
type: 'redis',
31+
prefix: 'jwt-example',
32+
secret: process.env.JWT_CLIENT_SECRET,
33+
url: process.env.REDIS_URL
34+
}
35+
}
36+
1237
const app = new Express();
1338

14-
jwtProxy(app, {
15-
authenticationEndpoint: `${process.env.AUTHENTICATION_HOST}/oauth/token`, // required
16-
jwtClientSecret: process.env.JWT_CLIENT_SECRET,
17-
jwtClientId: process.env.JWT_CLIENT_ID,
18-
tokenOverride: process.env.JWT_TOKEN_OVERRIDE,
19-
sessionSecret: process.env.SESSION_SECRET, // required
20-
// store in memory, when not using redis
21-
// sessionConfig: {
22-
// resave: false,
23-
// saveUninitialized: false
24-
// },
25-
// store using redis
26-
redisConfig: {
27-
prefix: 'my-app-name',
28-
host: '127.0.0.1',
29-
port: 6379
30-
},
31-
apiPrefix: config.apiPrefix,
32-
apiPrefixForService: config.apiPrefixForService,
33-
apiHost: config.apiHost, // required
34-
apiPort: config.apiPort, // required
35-
debug: false
36-
});
39+
jwtProxy(app, authConfig);
3740
```
3841

3942
You should then be able to use the following routes:
@@ -50,9 +53,9 @@ In your subsequent middleware, you'll be able to access the login state by using
5053
const loggedIn = res._headers['logged-in'] === "true";
5154
```
5255

53-
## TODO / Help Wanted
56+
## Examples
5457

55-
- Examples
58+
- [Using Universal Redux npm package](https://github.com/bdefore/universal-redux/tree/0.x/examples/jwt)
5659

5760
## Inspiration
5861

0 commit comments

Comments
 (0)