| 1 |
package oidc |
| 2 |
|
| 3 |
import "github.com/muhlemmer/gu" |
| 4 |
|
| 5 |
type IntrospectionRequest struct { |
| 6 |
Token string `schema:"token"` |
| 7 |
} |
| 8 |
|
| 9 |
type ClientAssertionParams struct { |
| 10 |
ClientAssertion string `schema:"client_assertion"` |
| 11 |
ClientAssertionType string `schema:"client_assertion_type"` |
| 12 |
} |
| 13 |
|
| 14 |
// IntrospectionResponse implements RFC 7662, section 2.2 and |
| 15 |
// OpenID Connect Core 1.0, section 5.1 (UserInfo). |
| 16 |
// https://www.rfc-editor.org/rfc/rfc7662.html#section-2.2. |
| 17 |
// https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims. |
| 18 |
type IntrospectionResponse struct { |
| 19 |
Active bool `json:"active"` |
| 20 |
Scope SpaceDelimitedArray `json:"scope,omitempty"` |
| 21 |
ClientID string `json:"client_id,omitempty"` |
| 22 |
TokenType string `json:"token_type,omitempty"` |
| 23 |
Expiration Time `json:"exp,omitempty"` |
| 24 |
IssuedAt Time `json:"iat,omitempty"` |
| 25 |
AuthTime Time `json:"auth_time,omitempty"` |
| 26 |
NotBefore Time `json:"nbf,omitempty"` |
| 27 |
Subject string `json:"sub,omitempty"` |
| 28 |
Audience Audience `json:"aud,omitempty"` |
| 29 |
AuthenticationMethodsReferences AuthenticationMethodsReferences `json:"amr,omitempty"` |
| 30 |
Issuer string `json:"iss,omitempty"` |
| 31 |
JWTID string `json:"jti,omitempty"` |
| 32 |
Username string `json:"username,omitempty"` |
| 33 |
Actor *ActorClaims `json:"act,omitempty"` |
| 34 |
UserInfoProfile |
| 35 |
UserInfoEmail |
| 36 |
UserInfoPhone |
| 37 |
|
| 38 |
Address *UserInfoAddress `json:"address,omitempty"` |
| 39 |
Claims map[string]any `json:"-"` |
| 40 |
} |
| 41 |
|
| 42 |
// SetUserInfo copies all relevant fields from UserInfo |
| 43 |
// into the IntrospectionResponse. |
| 44 |
func (i *IntrospectionResponse) SetUserInfo(u *UserInfo) { |
| 45 |
i.Subject = u.Subject |
| 46 |
i.Username = u.PreferredUsername |
| 47 |
i.Address = gu.PtrCopy(u.Address) |
| 48 |
i.UserInfoProfile = u.UserInfoProfile |
| 49 |
i.UserInfoEmail = u.UserInfoEmail |
| 50 |
i.UserInfoPhone = u.UserInfoPhone |
| 51 |
if i.Claims == nil { |
| 52 |
i.Claims = gu.MapCopy(u.Claims) |
| 53 |
} else { |
| 54 |
gu.MapMerge(u.Claims, i.Claims) |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
// GetAddress is a safe getter that takes |
| 59 |
// care of a possible nil value. |
| 60 |
func (i *IntrospectionResponse) GetAddress() *UserInfoAddress { |
| 61 |
if i.Address == nil { |
| 62 |
return new(UserInfoAddress) |
| 63 |
} |
| 64 |
return i.Address |
| 65 |
} |
| 66 |
|
| 67 |
// introspectionResponseAlias prevents loops on the JSON methods |
| 68 |
type introspectionResponseAlias IntrospectionResponse |
| 69 |
|
| 70 |
func (i *IntrospectionResponse) MarshalJSON() ([]byte, error) { |
| 71 |
if i.Username == "" { |
| 72 |
i.Username = i.PreferredUsername |
| 73 |
} |
| 74 |
return mergeAndMarshalClaims((*introspectionResponseAlias)(i), i.Claims) |
| 75 |
} |
| 76 |
|
| 77 |
func (i *IntrospectionResponse) UnmarshalJSON(data []byte) error { |
| 78 |
return unmarshalJSONMulti(data, (*introspectionResponseAlias)(i), &i.Claims) |
| 79 |
} |