aws-samples / aws-samples/lambdaedge-openidconnect-samples

The `subject` field used in the JWT causes unknown error when using Microsoft AD / OIDC

Open
#51 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
73
Forks
22
Avg merge
19h 45m
Merged PRs (30d)
1

Description

Microsoft AD/OIDC will not return the `email` claim even if the email scope is requested.

On [Line 339](https://github.com/aws-samples/lambdaedge-openidconnect-samples/blob/b4131275945f8ab0f6f4433b199950575db7c8fc/src/js/auth.js#L339) the cookie is set with a signed JSON Web Token containing a `subject` field that requires `decodedToken.payload.email`, however when that `email` claim is not present the code 500 errors with no details.

Switching to `decodedToken.payload.unique_name` fixes the problem when using Microsoft AD - however whether this is a breaking change for other providers I don't know.

I would like to see a more dynamic why to get the subject for the JWT, or at least extra documentation pointing out this potential issue.

In my code I have replaced any `decodedToken.payload.email` with `getSubject(decodedToken)` and added the following function to the bottom of my `auth.js` file:

```javascript
// getSubject returns a unique identify suitable for the subject field
function getSubject(decodedToken) {
return decodedToken.payload.email || decodedToken.payload.unique_name;
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.