@@ -622,8 +622,7 @@ func (s *IDPServer) issueTokens(w http.ResponseWriter, r *http.Request, ar *Auth
622622 return
623623 }
624624
625- // Add new access token and refresh token to the token store
626- at := rands .HexString (32 )
625+ at := token
627626 rt := rands .HexString (32 )
628627
629628 s .mu .Lock ()
@@ -910,6 +909,9 @@ func (s *IDPServer) serveIntrospect(w http.ResponseWriter, r *http.Request) {
910909 resp ["scope" ] = strings .Join (ar .Scopes , " " )
911910 }
912911
912+ // Include extra claims from capability if present (best-effort)
913+ addExtraClaims (resp , ar )
914+
913915 // Include act claim if present (RFC 8693)
914916 if ar .ActorInfo != nil {
915917 resp ["act" ] = ar .ActorInfo
@@ -949,3 +951,20 @@ func (ar *AuthRequest) allowRelyingParty(r *http.Request) (int, error) {
949951 }
950952 return http .StatusOK , nil
951953}
954+
955+ // addExtraClaims adds extra claims from the user's capabilities to the response map.
956+ // It does not overwrite existing keys in the response.
957+ func addExtraClaims (resp map [string ]any , ar * AuthRequest ) {
958+ if ar .RemoteUser == nil || ar .RemoteUser .CapMap == nil {
959+ return
960+ }
961+ rules , err := tailcfg .UnmarshalCapJSON [capRule ](ar .RemoteUser .CapMap , tailcfg .PeerCapabilityTsIDP )
962+ if err != nil {
963+ return
964+ }
965+ for k , v := range flattenExtraClaims (rules ) {
966+ if _ , exists := resp [k ]; ! exists {
967+ resp [k ] = v
968+ }
969+ }
970+ }
0 commit comments