Carries the raw ID token in the session cookie so logout can hand it back to Keycloak as id_token_hint, letting it skip its own logout-confirmation prompt -- otherwise a user could cancel out of it and land back in the app with a Keycloak SSO session but no geniusrun profile (e.g. right after deleting their account).
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
// Package mock provides a fake auth.Verifier for tests that need to exercise
|
|
// internal/api's session endpoints and RequireSession gating without a real
|
|
// Keycloak instance.
|
|
package mock
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
|
|
"geniusrun/backend/internal/auth"
|
|
)
|
|
|
|
// Verifier is a fake auth.Verifier returning canned results supplied by the
|
|
// test/caller.
|
|
type Verifier struct {
|
|
AuthURL string
|
|
Txn auth.TxnState
|
|
CallbackResult auth.LoginResult
|
|
CallbackErr error
|
|
EndSessionResult string // if empty, EndSessionURL returns postLogoutRedirectURL unchanged
|
|
LastIDTokenHint string // records the idTokenHint passed to the last EndSessionURL call
|
|
}
|
|
|
|
var _ auth.Verifier = (*Verifier)(nil)
|
|
|
|
func (v *Verifier) BeginLogin() (string, auth.TxnState, error) {
|
|
return v.AuthURL, v.Txn, nil
|
|
}
|
|
|
|
func (v *Verifier) HandleCallback(ctx context.Context, txn auth.TxnState, query url.Values) (auth.LoginResult, error) {
|
|
if v.CallbackErr != nil {
|
|
return auth.LoginResult{}, v.CallbackErr
|
|
}
|
|
return v.CallbackResult, nil
|
|
}
|
|
|
|
func (v *Verifier) EndSessionURL(postLogoutRedirectURL, idTokenHint string) string {
|
|
v.LastIDTokenHint = idTokenHint
|
|
if v.EndSessionResult != "" {
|
|
return v.EndSessionResult
|
|
}
|
|
return postLogoutRedirectURL
|
|
}
|