@@ -336,15 +336,12 @@ func tsproxy(ctx context.Context) error {
336
336
if upstream .OIDCIssuer != "" {
337
337
baseURL := "https://" + strings .TrimSuffix (st .Self .DNSName , "." )
338
338
339
- oidcm := & middleware.Handler {
340
- Issuer : upstream .OIDCIssuer ,
341
- ClientID : upstream .OIDCClientID ,
342
- ClientSecret : upstream .OIDCClientSecret ,
343
- BaseURL : baseURL ,
344
- RedirectURL : baseURL + "/.tsproxy/oidc-callback" ,
345
- SessionStore : & cookieAuthSession {},
346
- AdditionalScopes : []string {"profile" }, // make sure we have email etc.
339
+ oidcm , err := middleware .NewFromDiscovery (ctx , nil , upstream .OIDCIssuer , upstream .OIDCClientID , upstream .OIDCClientSecret , baseURL + "/.tsproxy/oidc-callback" )
340
+ if err != nil {
341
+ return fmt .Errorf ("oidc: new middleware: %w" , err )
347
342
}
343
+ oidcm .OAuth2Config .Scopes = append (oidcm .OAuth2Config .Scopes , "profile" , "email" )
344
+
348
345
mux .Handle ("/" , oidcm .Wrap (rp )) // fallback to authed path.
349
346
} else if ! slices .Contains (upstream .FunnelPublicPatterns , "/" ) {
350
347
// no OIDC auth, no root pattern, default behaviour is to block.
@@ -418,18 +415,21 @@ func newReverseProxy(logger *slog.Logger, lc tailscaleLocalClient, url *url.URL,
418
415
displayName := whois .UserProfile .DisplayName
419
416
420
417
if isFunnel {
421
- cl := middleware .ClaimsFromContext (r .Context ())
422
- if cl != nil {
423
- email := cl .Extra ["email" ].(string )
424
- name := cl .Extra ["name" ].(string )
425
- if email == "" || name == "" {
426
- http .Error (w , http .StatusText (http .StatusInternalServerError ), http .StatusInternalServerError )
427
- logger .Error ("oidc id token missing name or email" , slog .String ("email" , email ), slog .String ("name" , name ))
428
- return
429
- }
430
- loginName = email
431
- displayName = name
418
+ idt := middleware .IDJWTFromContext (r .Context ())
419
+ if idt == nil || ! idt .HasStringClaim ("name" ) || ! idt .HasStringClaim ("email" ) {
420
+ http .Error (w , http .StatusText (http .StatusInternalServerError ), http .StatusInternalServerError )
421
+ logger .Error ("oidc id token missing name or email" )
422
+ return
423
+ }
424
+ email , eerr := idt .StringClaim ("email" )
425
+ name , nerr := idt .StringClaim ("name" )
426
+ if eerr != nil || nerr != nil {
427
+ http .Error (w , http .StatusText (http .StatusInternalServerError ), http .StatusInternalServerError )
428
+ logger .Error ("oidc id token cannot unpack name or email" , "eerr" , eerr , "nerr" , nerr )
429
+ return
432
430
}
431
+ loginName = email
432
+ displayName = name
433
433
}
434
434
435
435
req := r .Clone (r .Context ())
0 commit comments