aws-samples / aws-samples/lambdaedge-openidconnect-samples
The `subject` field used in the JWT causes unknown error when using Microsoft AD / OIDC
- Lenguaje dominante
- JavaScript
- Estrellas
- 73
- Forks
- 22
- Merge medio
- 19 h 45 min
- PR fusionados (30 d)
- 1
Descripción
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;
}
```
Guía de contribución
Línea de trabajo
Comienza en src/js/auth.js en la línea 339 y sigue cómo se usa decodedToken.payload.email al crear el subject del JWT firmado. Compara los claims disponibles de Microsoft AD/OIDC que se muestran en el issue y, después, define y verifica el comportamiento para los proveedores con y sin email; el trabajo estará terminado cuando el flujo ya no devuelva un 500 inexplicado para la configuración indicada.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript
- Área
- authentication
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100