logout token
This commit is contained in:
parent
1a0238155c
commit
4a0afb04df
2 changed files with 73 additions and 0 deletions
|
@ -382,3 +382,40 @@ type TokenExchangeResponse struct {
|
||||||
// if the requested_token_type was Access Token and scope contained openid.
|
// if the requested_token_type was Access Token and scope contained openid.
|
||||||
IDToken string `json:"id_token,omitempty"`
|
IDToken string `json:"id_token,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LogoutTokenClaims struct {
|
||||||
|
Issuer string `json:"iss,omitempty"`
|
||||||
|
Subject string `json:"sub,omitempty"`
|
||||||
|
Audience Audience `json:"aud,omitempty"`
|
||||||
|
IssuedAt Time `json:"iat,omitempty"`
|
||||||
|
Expiration Time `json:"exp,omitempty"`
|
||||||
|
JWTID string `json:"jti,omitempty"`
|
||||||
|
Events map[string]any `json:"events,omitempty"`
|
||||||
|
SessionID string `json:"sid,omitempty"`
|
||||||
|
Claims map[string]any `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ltcAlias LogoutTokenClaims
|
||||||
|
|
||||||
|
func (i *LogoutTokenClaims) MarshalJSON() ([]byte, error) {
|
||||||
|
return mergeAndMarshalClaims((*ltcAlias)(i), i.Claims)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *LogoutTokenClaims) UnmarshalJSON(data []byte) error {
|
||||||
|
return unmarshalJSONMulti(data, (*ltcAlias)(i), &i.Claims)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLogoutTokenClaims(issuer, subject string, audience Audience, expiration time.Time, jwtID, sessionID string, skew time.Duration) *LogoutTokenClaims {
|
||||||
|
return &LogoutTokenClaims{
|
||||||
|
Issuer: issuer,
|
||||||
|
Subject: subject,
|
||||||
|
Audience: audience,
|
||||||
|
IssuedAt: FromTime(time.Now().Add(-skew)),
|
||||||
|
Expiration: FromTime(expiration),
|
||||||
|
JWTID: jwtID,
|
||||||
|
Events: map[string]any{
|
||||||
|
"http://schemas.openid.net/event/backchannel-logout": struct{}{},
|
||||||
|
},
|
||||||
|
SessionID: sessionID,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -242,3 +242,39 @@ func TestIDTokenClaims_GetUserInfo(t *testing.T) {
|
||||||
got := idTokenData.GetUserInfo()
|
got := idTokenData.GetUserInfo()
|
||||||
assert.Equal(t, want, got)
|
assert.Equal(t, want, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewLogoutTokenClaims(t *testing.T) {
|
||||||
|
want := &LogoutTokenClaims{
|
||||||
|
Issuer: "zitadel",
|
||||||
|
Subject: "hello@me.com",
|
||||||
|
Audience: Audience{"foo", "just@me.com"},
|
||||||
|
Expiration: 12345,
|
||||||
|
JWTID: "jwtID",
|
||||||
|
Events: map[string]any{
|
||||||
|
"http://schemas.openid.net/event/backchannel-logout": struct{}{},
|
||||||
|
},
|
||||||
|
SessionID: "sessionID",
|
||||||
|
Claims: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
got := NewLogoutTokenClaims(
|
||||||
|
want.Issuer,
|
||||||
|
want.Subject,
|
||||||
|
want.Audience,
|
||||||
|
want.Expiration.AsTime(),
|
||||||
|
want.JWTID,
|
||||||
|
want.SessionID,
|
||||||
|
1*time.Second,
|
||||||
|
)
|
||||||
|
|
||||||
|
// test if the dynamic timestamp is around now,
|
||||||
|
// allowing for a delta of 1, just in case we flip on
|
||||||
|
// either side of a second boundry.
|
||||||
|
nowMinusSkew := NowTime() - 1
|
||||||
|
assert.InDelta(t, int64(nowMinusSkew), int64(got.IssuedAt), 1)
|
||||||
|
|
||||||
|
// Make equal not fail on dynamic timestamp
|
||||||
|
got.IssuedAt = 0
|
||||||
|
|
||||||
|
assert.Equal(t, want, got)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue