Documentation
¶
Index ¶
- Constants
- Variables
- type APIError
- type AuthCode
- type Client
- type ClientRegistration
- type CreateTokenInput
- type Device
- type DeviceAuthorization
- type Handler
- func (h *Handler) ChaosOperations() []string
- func (h *Handler) ChaosRegions() []string
- func (h *Handler) ChaosServiceName() string
- func (h *Handler) ExtractOperation(c *echo.Context) string
- func (h *Handler) ExtractResource(_ *echo.Context) string
- func (h *Handler) GetSupportedOperations() []string
- func (h *Handler) Handler() echo.HandlerFunc
- func (h *Handler) MatchPriority() int
- func (h *Handler) Name() string
- func (h *Handler) Reset()
- func (h *Handler) Restore(ctx context.Context, data []byte) error
- func (h *Handler) RouteMatcher() service.Matcher
- func (h *Handler) ServeAuthorize(c *echo.Context) error
- func (h *Handler) ServeDeviceVerification(c *echo.Context) error
- func (h *Handler) SetSubjectResolver(r SubjectResolver)
- func (h *Handler) Snapshot(ctx context.Context) []byte
- type InMemoryBackend
- func (b *InMemoryBackend) ApproveDevice(userCode string, subject Subject) error
- func (b *InMemoryBackend) CreateToken(in *CreateTokenInput, iamCaller bool) (*TokenResult, *APIError)
- func (b *InMemoryBackend) DenyDevice(userCode string) error
- func (b *InMemoryBackend) DeviceUserCodeValid(userCode string) bool
- func (b *InMemoryBackend) IssueAuthCode(clientID, redirectURI, challenge, method string, subject Subject) (string, *APIError)
- func (b *InMemoryBackend) RegisterClient(in *RegisterClientInput) (*ClientRegistration, *APIError)
- func (b *InMemoryBackend) Reset()
- func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
- func (b *InMemoryBackend) RevokeSession(token string) error
- func (b *InMemoryBackend) SessionForAccessToken(token string) (Session, error)
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- func (b *InMemoryBackend) StartDeviceAuthorization(clientID, clientSecret, startURL string) (*DeviceAuthorization, *APIError)
- type Provider
- type RegisterClientInput
- type Session
- type Subject
- type SubjectResolver
- type Token
- type TokenResult
Constants ¶
const ( DevicePath = "/_gopherstack/sso/device" AuthorizePath = "/_gopherstack/sso/authorize" )
Emulator-only browser endpoints behind verificationUri and authorizationEndpoint.
Variables ¶
var ( ErrUnknownUserCode = errors.New("unknown or expired user code") ErrUnknownUser = errors.New("unknown user") ErrTokenNotFound = errors.New("session token not found or invalid") ErrTokenExpired = errors.New("session token expired") ErrNoResolver = errors.New("no identity resolver is wired") )
Sentinels for the approval endpoints and the portal's token lookup.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
APIError is an OIDC protocol error: Code is the exception name, OAuth the RFC 6749 "error" value.
type AuthCode ¶
type AuthCode struct {
ExpiresAt time.Time `json:"expiresAt"`
Subject Subject `json:"subject"`
Code string `json:"code"`
ClientID string `json:"clientId"`
RedirectURI string `json:"redirectUri"`
CodeChallenge string `json:"codeChallenge"`
}
AuthCode is a single-use authorization code awaiting CreateToken.
type Client ¶
type Client struct {
IssuedAt time.Time `json:"issuedAt"`
ExpiresAt time.Time `json:"expiresAt"`
ClientID string `json:"clientId"`
ClientSecret string `json:"clientSecret"`
ClientName string `json:"clientName"`
IssuerURL string `json:"issuerUrl,omitempty"`
EntitledApp string `json:"entitledApplicationArn,omitempty"`
GrantTypes []string `json:"grantTypes,omitempty"`
RedirectURIs []string `json:"redirectUris,omitempty"`
Scopes []string `json:"scopes,omitempty"`
}
Client is a public client registered by RegisterClient.
type ClientRegistration ¶
type ClientRegistration struct {
ClientID string
ClientSecret string
ClientIDIssuedAt int64
ClientSecretExpiresAt int64
}
ClientRegistration is the outcome of RegisterClient.
type CreateTokenInput ¶
type CreateTokenInput struct {
ClientID string
ClientSecret string
GrantType string
Code string
CodeVerifier string
DeviceCode string
RedirectURI string
RefreshToken string
}
CreateTokenInput carries the CreateToken and CreateTokenWithIAM request members.
type Device ¶
type Device struct {
ExpiresAt time.Time `json:"expiresAt"`
LastPolled time.Time `json:"lastPolled"`
Subject Subject `json:"subject"`
DeviceCode string `json:"deviceCode"`
UserCode string `json:"userCode"`
ClientID string `json:"clientId"`
StartURL string `json:"startUrl"`
Status string `json:"status"`
Interval int32 `json:"interval"`
}
Device is one in-flight StartDeviceAuthorization request.
type DeviceAuthorization ¶
type DeviceAuthorization struct {
DeviceCode string
UserCode string
ExpiresIn int32
Interval int32
}
DeviceAuthorization is the outcome of StartDeviceAuthorization.
type Handler ¶
type Handler struct {
Backend *InMemoryBackend
// contains filtered or unexported fields
}
Handler is the Echo handler for the IAM Identity Center OIDC API.
func NewHandler ¶
func NewHandler(backend *InMemoryBackend) *Handler
NewHandler creates a Handler over backend.
func (*Handler) ChaosOperations ¶
ChaosOperations returns the fault-injectable operations.
func (*Handler) ChaosRegions ¶
ChaosRegions returns the regions served.
func (*Handler) ChaosServiceName ¶
ChaosServiceName returns the lowercase service name for fault rules.
func (*Handler) ExtractOperation ¶
ExtractOperation returns the operation name.
func (*Handler) ExtractResource ¶
ExtractResource returns a fixed label to avoid high-cardinality metrics.
func (*Handler) GetSupportedOperations ¶
GetSupportedOperations returns the supported operations.
func (*Handler) Handler ¶
func (h *Handler) Handler() echo.HandlerFunc
Handler returns the Echo handler.
func (*Handler) MatchPriority ¶
MatchPriority returns the routing priority.
func (*Handler) RouteMatcher ¶
RouteMatcher matches the OIDC endpoints. The SDK sends these calls unsigned, so an S3-signed request or one carrying query parameters (an S3 subresource) is not ours.
func (*Handler) ServeAuthorize ¶
ServeAuthorize implements the authorization-code endpoint: it signs in the requested (or default) user and redirects to redirect_uri with a single-use code, requiring a PKCE S256 challenge.
func (*Handler) ServeDeviceVerification ¶
ServeDeviceVerification serves the device-code verification page. With action=approve or action=deny (query or form) it completes the authorization; user selects the signed-in user.
func (*Handler) SetSubjectResolver ¶
func (h *Handler) SetSubjectResolver(r SubjectResolver)
SetSubjectResolver wires the directory used to resolve users on sign-in approval.
type InMemoryBackend ¶
type InMemoryBackend struct {
// contains filtered or unexported fields
}
InMemoryBackend holds every OIDC client, in-flight authorization and issued token.
func NewInMemoryBackend ¶
func NewInMemoryBackend() *InMemoryBackend
NewInMemoryBackend creates an empty backend.
func (*InMemoryBackend) ApproveDevice ¶
func (b *InMemoryBackend) ApproveDevice(userCode string, subject Subject) error
ApproveDevice marks the authorization for userCode approved for subject.
func (*InMemoryBackend) CreateToken ¶
func (b *InMemoryBackend) CreateToken(in *CreateTokenInput, iamCaller bool) (*TokenResult, *APIError)
CreateToken exchanges a device code, authorization code or refresh token for tokens. IAM-authenticated callers (CreateTokenWithIAM) present no client secret.
func (*InMemoryBackend) DenyDevice ¶
func (b *InMemoryBackend) DenyDevice(userCode string) error
DenyDevice marks the authorization for userCode denied.
func (*InMemoryBackend) DeviceUserCodeValid ¶
func (b *InMemoryBackend) DeviceUserCodeValid(userCode string) bool
DeviceUserCodeValid reports whether userCode names a pending, unexpired authorization.
func (*InMemoryBackend) IssueAuthCode ¶
func (b *InMemoryBackend) IssueAuthCode( clientID, redirectURI, challenge, method string, subject Subject, ) (string, *APIError)
IssueAuthCode validates an authorization request and returns a single-use code bound to its PKCE challenge.
func (*InMemoryBackend) RegisterClient ¶
func (b *InMemoryBackend) RegisterClient(in *RegisterClientInput) (*ClientRegistration, *APIError)
RegisterClient registers a public client.
func (*InMemoryBackend) Restore ¶
func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
Restore loads backend state; an incompatible version starts empty.
func (*InMemoryBackend) RevokeSession ¶
func (b *InMemoryBackend) RevokeSession(token string) error
RevokeSession deletes every token of the sign-in session that issued token.
func (*InMemoryBackend) SessionForAccessToken ¶
func (b *InMemoryBackend) SessionForAccessToken(token string) (Session, error)
SessionForAccessToken resolves a bearer access token to its sign-in session.
func (*InMemoryBackend) Snapshot ¶
func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
Snapshot serializes the backend state. It implements persistence.Persistable.
func (*InMemoryBackend) StartDeviceAuthorization ¶
func (b *InMemoryBackend) StartDeviceAuthorization( clientID, clientSecret, startURL string, ) (*DeviceAuthorization, *APIError)
StartDeviceAuthorization opens a device authorization for a registered client.
type Provider ¶
type Provider struct{}
Provider implements service.Provider for the IAM Identity Center OIDC API.
func (*Provider) Init ¶
func (p *Provider) Init(_ *service.AppContext) (service.Registerable, error)
Init builds the backend and handler.
type RegisterClientInput ¶
type RegisterClientInput struct {
ClientName string
ClientType string
IssuerURL string
EntitledApp string
GrantTypes []string
RedirectURIs []string
Scopes []string
}
RegisterClientInput carries the RegisterClient request members.
type Subject ¶
type Subject struct {
UserName string `json:"userName,omitempty"`
UserID string `json:"userId,omitempty"`
IdentityStoreID string `json:"identityStoreId,omitempty"`
}
Subject is the Identity Center user a device or authorization-code approval signs in.
type SubjectResolver ¶
SubjectResolver maps an Identity Center user name to the subject a sign-in approval acts for. An empty userName selects the default user.
type Token ¶
type Token struct {
ExpiresAt time.Time `json:"expiresAt"`
Subject Subject `json:"subject"`
Token string `json:"token"`
Kind string `json:"kind"`
ClientID string `json:"clientId"`
SessionID string `json:"sessionId"`
StartURL string `json:"startUrl,omitempty"`
Scopes []string `json:"scopes,omitempty"`
}
Token is an issued access or refresh token.