Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bump openid-client #12

Merged
merged 1 commit into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
language: node_js
node_js:
- "8"
- 10.13.0
- 10
- 12.0.0
- 12
- stable
8 changes: 4 additions & 4 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ In general, you won't need to configure this middleware besides the required par
| clientID | `env.CLIENT_ID` | The client id. |
| clientSecret | `env.CLIENT_SECRET` | The client secret, only required for some grants. |
| clockTolerance | `5` | The clock's tolerance in seconds for token verification. |
| getUser | `tokenSet => tokenSet.claims` | An async function receiving a tokenset and returning the profile for `req.openid.user`. |
| getUser | `tokenSet => tokenSet.claims()` | An async function receiving a tokenset and returning the profile for `req.openid.user`. |
| required | `true` | If true requires authentication for all the routes in the stack. You can also provide a function to determine if is required based on the request. |
| handleUnauthorizedErrors | `true` | Install a middleware that handles Unauthorized/401 errors by triggering the login process. |
| routes | `true` | Installs the `GET /login` and `GET /logout` route. |
Expand Down Expand Up @@ -70,13 +70,13 @@ app.use(auth());

## Session and Context

The middleware store the [openid-client TokenSet](https://www.npmjs.com/package/openid-client#tokenset) in the user's session.
The middleware store the [openid-client TokenSet](https://github.com/panva/node-openid-client/blob/master/docs/README.md#tokenset) in the user's session.

Every `req` object is augmented with the following properties when the request is authenticated

- `req.openid.user`: contains the user information, use this if you need display an attribute of the user. You can change what's end up here by using the `getUser` parameter of the `auth` middleware.
- `req.openid.tokens`: is the instance of [TokenSet](https://www.npmjs.com/package/openid-client#tokenset).
- `req.openid.client`: is an instance of te [OpenID Client](https://www.npmjs.com/package/openid-client).
- `req.openid.tokens`: is the instance of [TokenSet](https://github.com/panva/node-openid-client/blob/master/docs/README.md#tokenset).
- `req.openid.client`: is an instance of te [OpenID Client](https://github.com/panva/node-openid-client/blob/master/docs/README.md#client).
- `req.isAuthenticated()`: returns true if the request is authenticated.

If the request is not authenticated `req.openid` is `undefined`.
Expand Down
10 changes: 4 additions & 6 deletions lib/client.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
const { Issuer } = require('openid-client');
const { Issuer, custom } = require('openid-client');
const memoize = require('p-memoize');
const url = require('url');
const urlJoin = require('url-join');
const pkg = require('../package.json');

Issuer.defaultHttpOptions = {
custom.setHttpOptionsDefaults({
headers: {
'User-Agent': `${pkg.name}/${pkg.version} (${pkg.homepage})`
},
timeout: 4000
};

Issuer.useRequest();
});

async function get(config) {
const authorizeParams = config.authorizationParams;
Expand Down Expand Up @@ -54,7 +52,7 @@ Supported response modes:
}
}

client.CLOCK_TOLERANCE = config.clockTolerance;
client[custom.clock_tolerance] = config.clockTolerance;

return client;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/getUser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//This is the default function for mapping a tokenSet to a user.
module.exports = function(tokenSet) {
return tokenSet && tokenSet.claims;
return tokenSet && tokenSet.claims();
};
2 changes: 1 addition & 1 deletion middleware/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ module.exports = function (params) {
try {
const callbackParams = client.callbackParams(req);
debugCallback('callback parameters: %O', callbackParams);
tokenSet = await client.authorizationCallback(redirect_uri, callbackParams, {
tokenSet = await client.callback(redirect_uri, callbackParams, {
nonce,
state,
response_type: authorizeParams.response_type,
Expand Down
Loading