@@ -8,32 +8,35 @@ An Express middleware to route login requests to an external authentication serv
8
8
9
9
## Usage
10
10
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
+
12
37
const app = new Express ();
13
38
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);
37
40
```
38
41
39
42
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
50
53
const loggedIn = res._headers['logged-in'] === "true";
51
54
```
52
55
53
- ## TODO / Help Wanted
56
+ ## Examples
54
57
55
- - Examples
58
+ - [ Using Universal Redux npm package ] ( https://github.com/bdefore/universal-redux/tree/0.x/examples/jwt )
56
59
57
60
## Inspiration
58
61
0 commit comments