Skip to content

Commit

Permalink
Update example for userinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
joshcanhelp committed Jan 3, 2020
1 parent a2ada61 commit 69572c6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
3 changes: 2 additions & 1 deletion EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,13 @@ app.get('/route-that-calls-an-api', async (req, res, next) => {
## 7. Calling userinfo
If your application needs to call the userinfo endpoint for the user's identity instead of the ID token used by default, add a `handleCallback` function during initialization that will make this call. To map the incoming claims to the user identity, also add a `getUser` function.
If your application needs to call the userinfo endpoint for the user's identity instead of the ID token used by default, add a `handleCallback` function during initialization that will make this call. Save the claims retrieved from the userinfo endpoint to the `appSessionName` on the request object (default is `identity`):
```js
app.use(auth({
handleCallback: async function (req, res, next) {
const client = req.openid.client;
req.identity = req.identity || {};
try {
req.identity.claims = await client.userinfo(req.openidTokens);
next();
Expand Down
3 changes: 1 addition & 2 deletions lib/hooks/getUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
*/
module.exports = function(req, config) {

// If there is no appSessionSecret, session handing is custom.
if (!config.appSessionSecret || !req[config.appSessionName] || !req[config.appSessionName].claims) {
if (!req[config.appSessionName] || !req[config.appSessionName].claims) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion middleware/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ module.exports = function (params) {
throw createError.BadRequest(err.message);
}

req.openIdTokens = tokenSet;
req.openidTokens = tokenSet;

if (config.appSessionSecret) {
let identityClaims = tokenSet.claims();
Expand Down

0 comments on commit 69572c6

Please sign in to comment.