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

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

Aperta
#51 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
JavaScript
Stelle
73
Fork
22
Merge medio
19h 45m
PR unite (30g)
1

Descrizione

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;
}
```

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia in src/js/auth.js alla riga 339 e traccia come viene usato decodedToken.payload.email nella creazione del subject del JWT firmato. Confronta i claims Microsoft AD/OIDC disponibili mostrati nell’issue, quindi definisci e verifica il comportamento per i provider con e senza email; il lavoro è completato quando il flusso non restituisce più un 500 non spiegato per la configurazione segnalata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript
Ambito
authentication
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.