Documentation
¶
Index ¶
- func CreateClientWithID(clientID string, req ClientCreateRequest) error
- func DeleteClient(clientID string) error
- func FilterScopes(c *Client, requested string) string
- func GenerateClientID() (string, error)
- func GenerateClientSecret() (string, error)
- func HandleClientEndpoint(w http.ResponseWriter, r *http.Request)
- func HandleDeleteClient(w http.ResponseWriter, r *http.Request)
- func HandleGetClient(w http.ResponseWriter, r *http.Request)
- func HandleListClients(w http.ResponseWriter, r *http.Request)
- func HandleRegister(w http.ResponseWriter, r *http.Request)
- func HandleUpdateClient(w http.ResponseWriter, r *http.Request)
- func IsGrantTypeAllowed(client *Client, grantType string) bool
- func IsResponseTypeAllowed(client *Client, responseType string) bool
- func IsValidRedirectURI(client *Client, redirectURI string) bool
- func UpdateClient(clientID string, req ClientUpdateRequest) error
- func ValidateClientCreateRequest(input ClientCreateRequest) error
- func ValidateClientUpdateRequest(input ClientUpdateRequest) error
- func ValidateRedirectURIs(uris []string) error
- func ValidateScopes(c *Client, requested string) bool
- type Client
- type ClientCreateRequest
- type ClientInfoResponse
- type ClientResponse
- type ClientUpdateRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateClientWithID ¶
func CreateClientWithID(clientID string, req ClientCreateRequest) error
func DeleteClient ¶
DeleteClient performs a soft delete by setting is_active to false
func FilterScopes ¶ added in v1.2.0
FilterScopes returns the intersection of the requested scopes and the client's allowed scopes, preserving the original request order. If the client is nil or has no scopes configured, the requested scopes are returned unchanged.
func GenerateClientID ¶
GenerateClientID generates a unique client identifier
func GenerateClientSecret ¶
GenerateClientSecret generates a secure client secret
func HandleClientEndpoint ¶
func HandleClientEndpoint(w http.ResponseWriter, r *http.Request)
HandleClientEndpoint is a combined handler for /oauth2/register endpoints Routes requests based on method and path
func HandleDeleteClient ¶
func HandleDeleteClient(w http.ResponseWriter, r *http.Request)
HandleDeleteClient handles DELETE /oauth2/register/{client_id} - deactivates a client @Summary Deactivate a client @Description Deactivates (soft deletes) a registered client (admin only) @Tags client @Accept json @Produce json @Param client_id path string true "Client ID" @Success 204 "No Content" @Failure 404 {object} model.AuthErrorResponse @Router /oauth2/register/{client_id} [delete] @Router /admin/api/clients/{client_id} [delete]
func HandleGetClient ¶
func HandleGetClient(w http.ResponseWriter, r *http.Request)
HandleGetClient handles GET /oauth2/register/{client_id} - gets client info @Summary Get client information @Description Retrieves information about a registered client (admin only) @Tags client @Accept json @Produce json @Param client_id path string true "Client ID" @Success 200 {object} ClientInfoResponse @Failure 404 {object} model.AuthErrorResponse @Router /oauth2/register/{client_id} [get] @Router /admin/api/clients/{client_id} [get]
func HandleListClients ¶
func HandleListClients(w http.ResponseWriter, r *http.Request)
HandleListClients handles GET /oauth2/register - lists all clients @Summary List all clients @Description Lists all registered clients (admin only) @Tags client @Accept json @Produce json @Success 200 {array} ClientInfoResponse @Failure 500 {object} model.AuthErrorResponse @Router /oauth2/register [get] @Router /admin/api/clients [get]
func HandleRegister ¶
func HandleRegister(w http.ResponseWriter, r *http.Request)
HandleRegister handles POST /oauth2/register - creates a new client @Summary Register a new OAuth2 client @Description Registers a new OAuth2/OIDC client (admin only) @Tags client @Accept json @Produce json @Param request body ClientCreateRequest true "Client registration request" @Success 201 {object} ClientResponse @Failure 400 {object} model.AuthErrorResponse @Failure 401 {object} model.AuthErrorResponse @Failure 500 {object} model.AuthErrorResponse @Router /oauth2/register [post] @Router /admin/api/clients [post]
func HandleUpdateClient ¶
func HandleUpdateClient(w http.ResponseWriter, r *http.Request)
HandleUpdateClient handles PUT /oauth2/register/{client_id} - updates a client @Summary Update client information @Description Updates a registered client (admin only) @Tags client @Accept json @Produce json @Param client_id path string true "Client ID" @Param request body ClientUpdateRequest true "Client update request" @Success 200 {object} ClientInfoResponse @Failure 400 {object} model.AuthErrorResponse @Failure 404 {object} model.AuthErrorResponse @Router /oauth2/register/{client_id} [put] @Router /admin/api/clients/{client_id} [put]
func IsGrantTypeAllowed ¶
IsGrantTypeAllowed checks if the given grant type is allowed for the client
func IsResponseTypeAllowed ¶
IsResponseTypeAllowed checks if the given response type is allowed for the client
func IsValidRedirectURI ¶
IsValidRedirectURI checks if the given redirect URI is allowed for the client
func UpdateClient ¶
func UpdateClient(clientID string, req ClientUpdateRequest) error
func ValidateClientCreateRequest ¶
func ValidateClientCreateRequest(input ClientCreateRequest) error
ValidateClientCreateRequest validates a client registration request
func ValidateClientUpdateRequest ¶
func ValidateClientUpdateRequest(input ClientUpdateRequest) error
ValidateClientUpdateRequest validates a client update request
func ValidateRedirectURIs ¶
ValidateRedirectURIs validates that all redirect URIs are valid URLs
func ValidateScopes ¶ added in v1.2.0
ValidateScopes returns true if every requested scope is within the client's allowed scopes. Returns true unconditionally when the client is nil, has no scopes configured, or the requested scope string is empty.
Types ¶
type Client ¶
type Client struct {
ID string `db:"id"`
ClientID string `db:"client_id"`
ClientSecret string `db:"client_secret"`
ClientName string `db:"client_name"`
ClientType string `db:"client_type"`
RedirectURIs string `db:"redirect_uris"`
PostLogoutRedirectURIs string `db:"post_logout_redirect_uris"`
GrantTypes string `db:"grant_types"`
ResponseTypes string `db:"response_types"`
Scopes string `db:"scopes"`
TokenEndpointAuthMethod string `db:"token_endpoint_auth_method"`
IsActive bool `db:"is_active"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
// Per-client overrides — nil means "use global setting"
AccessTokenExpiration *string `db:"access_token_expiration"`
RefreshTokenExpiration *string `db:"refresh_token_expiration"`
AuthorizationCodeExpiration *string `db:"authorization_code_expiration"`
AllowedAudiences *string `db:"allowed_audiences"` // JSON array
AllowSelfSignup *bool `db:"allow_self_signup"`
SsoSessionIdleTimeout *string `db:"sso_session_idle_timeout"`
TrustDeviceEnabled *bool `db:"trust_device_enabled"`
TrustDeviceExpiration *string `db:"trust_device_expiration"`
}
Client represents an OAuth2/OIDC client in the database
func AuthenticateClient ¶
AuthenticateClient verifies the client credentials Returns the client if authentication succeeds, error otherwise
func AuthenticateClientFromRequest ¶
AuthenticateClientFromRequest extracts client credentials from the HTTP request and authenticates the client. Supports both Basic Auth and form parameters. Returns nil, nil if no client credentials are provided (backward compatibility)
func ClientByClientID ¶
func ClientByID ¶
func ListClients ¶
func (*Client) GetGrantTypes ¶
GetGrantTypes parses and returns the grant types as a slice
func (*Client) GetPostLogoutRedirectURIs ¶ added in v1.3.2
GetPostLogoutRedirectURIs parses and returns the post-logout redirect URIs as a slice
func (*Client) GetRedirectURIs ¶
GetRedirectURIs parses and returns the redirect URIs as a slice
func (*Client) GetResponseTypes ¶
GetResponseTypes parses and returns the response types as a slice
func (*Client) ToInfoResponse ¶
func (c *Client) ToInfoResponse() *ClientInfoResponse
ToInfoResponse converts a Client to a ClientInfoResponse
func (*Client) ToOverrides ¶
func (c *Client) ToOverrides() config.ClientOverrides
ToOverrides converts the nullable client override fields into a config.ClientOverrides struct, which can be passed to config.GetForClient() to resolve per-client settings.
type ClientCreateRequest ¶
type ClientCreateRequest struct {
ClientID string `json:"client_id,omitempty"`
ClientName string `json:"client_name"`
RedirectURIs []string `json:"redirect_uris"`
PostLogoutRedirectURIs []string `json:"post_logout_redirect_uris,omitempty"`
GrantTypes []string `json:"grant_types,omitempty"`
ResponseTypes []string `json:"response_types,omitempty"`
ClientType string `json:"client_type,omitempty"`
Scopes string `json:"scopes,omitempty"`
TokenEndpointAuthMethod string `json:"token_endpoint_auth_method,omitempty"`
// Per-client overrides
AccessTokenExpiration *string `json:"access_token_expiration,omitempty"`
RefreshTokenExpiration *string `json:"refresh_token_expiration,omitempty"`
AuthorizationCodeExpiration *string `json:"authorization_code_expiration,omitempty"`
AllowedAudiences []string `json:"allowed_audiences,omitempty"`
AllowSelfSignup *bool `json:"allow_self_signup,omitempty"`
SsoSessionIdleTimeout *string `json:"sso_session_idle_timeout,omitempty"`
TrustDeviceEnabled *bool `json:"trust_device_enabled,omitempty"`
TrustDeviceExpiration *string `json:"trust_device_expiration,omitempty"`
}
ClientCreateRequest represents the request body for client registration
type ClientInfoResponse ¶
type ClientInfoResponse struct {
ClientID string `json:"client_id"`
ClientName string `json:"client_name"`
ClientType string `json:"client_type"`
RedirectURIs []string `json:"redirect_uris"`
PostLogoutRedirectURIs []string `json:"post_logout_redirect_uris"`
GrantTypes []string `json:"grant_types"`
ResponseTypes []string `json:"response_types"`
Scopes string `json:"scopes"`
TokenEndpointAuthMethod string `json:"token_endpoint_auth_method"`
IsActive bool `json:"is_active"`
// Per-client overrides
AccessTokenExpiration *string `json:"access_token_expiration,omitempty"`
RefreshTokenExpiration *string `json:"refresh_token_expiration,omitempty"`
AuthorizationCodeExpiration *string `json:"authorization_code_expiration,omitempty"`
AllowedAudiences []string `json:"allowed_audiences,omitempty"`
AllowSelfSignup *bool `json:"allow_self_signup,omitempty"`
SsoSessionIdleTimeout *string `json:"sso_session_idle_timeout,omitempty"`
TrustDeviceEnabled *bool `json:"trust_device_enabled,omitempty"`
TrustDeviceExpiration *string `json:"trust_device_expiration,omitempty"`
}
ClientInfoResponse represents the response for getting client info (without secret)
type ClientResponse ¶
type ClientResponse struct {
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret,omitempty"`
ClientSecretExpiresAt int `json:"client_secret_expires_at"`
ClientName string `json:"client_name"`
ClientType string `json:"client_type"`
RedirectURIs []string `json:"redirect_uris"`
PostLogoutRedirectURIs []string `json:"post_logout_redirect_uris"`
GrantTypes []string `json:"grant_types"`
ResponseTypes []string `json:"response_types"`
Scopes string `json:"scopes"`
TokenEndpointAuthMethod string `json:"token_endpoint_auth_method"`
}
ClientResponse represents the response for client operations
func CreateClient ¶
func CreateClient(req ClientCreateRequest) (*ClientResponse, error)
type ClientUpdateRequest ¶
type ClientUpdateRequest struct {
ClientName string `json:"client_name,omitempty"`
RedirectURIs []string `json:"redirect_uris,omitempty"`
PostLogoutRedirectURIs []string `json:"post_logout_redirect_uris,omitempty"`
GrantTypes []string `json:"grant_types,omitempty"`
ResponseTypes []string `json:"response_types,omitempty"`
Scopes string `json:"scopes,omitempty"`
TokenEndpointAuthMethod string `json:"token_endpoint_auth_method,omitempty"`
IsActive *bool `json:"is_active,omitempty"`
// Per-client overrides
AccessTokenExpiration *string `json:"access_token_expiration,omitempty"`
RefreshTokenExpiration *string `json:"refresh_token_expiration,omitempty"`
AuthorizationCodeExpiration *string `json:"authorization_code_expiration,omitempty"`
AllowedAudiences []string `json:"allowed_audiences,omitempty"`
AllowSelfSignup *bool `json:"allow_self_signup,omitempty"`
SsoSessionIdleTimeout *string `json:"sso_session_idle_timeout,omitempty"`
TrustDeviceEnabled *bool `json:"trust_device_enabled,omitempty"`
TrustDeviceExpiration *string `json:"trust_device_expiration,omitempty"`
}
ClientUpdateRequest represents the request body for updating a client