Documentation ¶
Index ¶
- Constants
- func RequireSessionV2(client Client, verifyTokenOptions ...VerifyTokenOption) func(handler http.Handler) http.Handler
- func WithSession(client Client) func(handler http.Handler) http.Handler
- func WithSessionV2(client Client, verifyTokenOptions ...VerifyTokenOption) func(handler http.Handler) http.Handler
- type ClerkOption
- type Client
- type ClientResponse
- type ClientsService
- type CreateUpdateJWTTemplate
- type DeleteResponse
- type Email
- type EmailAddress
- type EmailResponse
- type EmailService
- type Error
- type ErrorResponse
- type IdentificationLink
- type InstanceService
- type JWKS
- type JWKSService
- type JWTTemplate
- type JWTTemplatesService
- func (s JWTTemplatesService) Create(params *CreateUpdateJWTTemplate) (*JWTTemplate, error)
- func (s JWTTemplatesService) Delete(id string) (*DeleteResponse, error)
- func (s JWTTemplatesService) ListAll() ([]JWTTemplate, error)
- func (s JWTTemplatesService) Read(id string) (*JWTTemplate, error)
- func (s JWTTemplatesService) Update(id string, params *CreateUpdateJWTTemplate) (*JWTTemplate, error)
- type ListAllOrganizationsParams
- type ListAllUsersParams
- type Organization
- type OrganizationsResponse
- type OrganizationsService
- type PhoneNumber
- type PreviewTemplateRequest
- type SMSMessage
- type SMSMessageResponse
- type SMSService
- type Session
- type SessionClaims
- type SessionsService
- type SvixResponse
- type Template
- type TemplateExtended
- type TemplatePreview
- type TemplatesService
- func (s *TemplatesService) Delete(templateType, slug string) (*DeleteResponse, error)
- func (s *TemplatesService) ListAll(templateType string) ([]Template, error)
- func (s *TemplatesService) Preview(templateType, slug string, previewTemplateRequest *PreviewTemplateRequest) (*TemplatePreview, error)
- func (s *TemplatesService) Read(templateType, slug string) (*TemplateExtended, error)
- func (s *TemplatesService) Revert(templateType, slug string) (*TemplateExtended, error)
- func (s *TemplatesService) Upsert(templateType, slug string, upsertTemplateRequest *UpsertTemplateRequest) (*TemplateExtended, error)
- type TokenClaims
- type UpdateInstanceParams
- type UpdateUser
- type UpdateUserMetadata
- type UpsertTemplateRequest
- type User
- type UserCount
- type UsersService
- func (s *UsersService) Count(params ListAllUsersParams) (*UserCount, error)
- func (s *UsersService) Delete(userId string) (*DeleteResponse, error)
- func (s *UsersService) ListAll(params ListAllUsersParams) ([]User, error)
- func (s *UsersService) Read(userId string) (*User, error)
- func (s *UsersService) Update(userId string, updateRequest *UpdateUser) (*User, error)
- func (s *UsersService) UpdateMetadata(userId string, updateMetadataRequest *UpdateUserMetadata) (*User, error)
- type VerificationService
- type VerifyTokenOption
- type WebhooksService
Constants ¶
const ( ProdUrl = "https://api.clerk.dev/v1/" ClientsUrl = "clients" ClientsVerifyUrl = ClientsUrl + "/verify" EmailsUrl = "emails" OrganizationsUrl = "organizations" SessionsUrl = "sessions" SMSUrl = "sms_messages" TemplatesUrl = "templates" UsersUrl = "users" UsersCountUrl = UsersUrl + "/count" WebhooksUrl = "webhooks" JWTTemplatesUrl = "jwt_templates" )
const ( ActiveSession = iota ActiveSessionClaims )
const ( CookieSession = "__session" QueryParamSessionId = "_clerk_session_id" )
Variables ¶
This section is empty.
Functions ¶
func RequireSessionV2 ¶ added in v1.1.0
func RequireSessionV2(client Client, verifyTokenOptions ...VerifyTokenOption) func(handler http.Handler) http.Handler
RequireSessionV2 will hijack the request and return an HTTP status 403 if the session is not authenticated.
func WithSession ¶ added in v1.0.3
func WithSessionV2 ¶ added in v1.1.0
func WithSessionV2(client Client, verifyTokenOptions ...VerifyTokenOption) func(handler http.Handler) http.Handler
WithSessionV2 is the new middleware that supports Auth v2. If the session is authenticated, it adds the corresponding session claims found in the JWT to request's context.
Types ¶
type ClerkOption ¶ added in v1.2.0
type ClerkOption func(*client) error
ClerkOption describes a functional parameter for the clerk client constructor
func WithBaseURL ¶ added in v1.2.0
func WithBaseURL(rawURL string) ClerkOption
WithBaseURL allows the overriding of the base URL
func WithHTTPClient ¶ added in v1.2.0
func WithHTTPClient(httpClient *http.Client) ClerkOption
WithHTTPClient allows the overriding of the http client
type Client ¶
type Client interface { NewRequest(method, url string, body ...interface{}) (*http.Request, error) Do(req *http.Request, v interface{}) (*http.Response, error) DecodeToken(token string) (*TokenClaims, error) VerifyToken(token string, opts ...VerifyTokenOption) (*SessionClaims, error) Clients() *ClientsService Emails() *EmailService Instances() *InstanceService JWKS() *JWKSService JWTTemplates() *JWTTemplatesService Organizations() *OrganizationsService Sessions() *SessionsService SMS() *SMSService Templates() *TemplatesService Users() *UsersService Webhooks() *WebhooksService Verification() *VerificationService Interstitial() ([]byte, error) APIKey() string }
func NewClient ¶
func NewClient(token string, options ...ClerkOption) (Client, error)
NewClient creates a new Clerk client. Because the token supplied will be used for all authenticated requests, the created client should not be used across different users
func NewClientWithBaseUrl
deprecated
type ClientResponse ¶ added in v1.0.3
type ClientResponse struct { Object string `json:"object"` ID string `json:"id"` LastActiveSessionID *string `json:"last_active_session_id"` SessionIDs []string `json:"session_ids"` Sessions []*Session `json:"sessions"` SignInAttemptID *string `json:"sign_in_attempt_id"` SignUpAttemptID *string `json:"sign_up_attempt_id"` Ended bool `json:"ended"` }
type ClientsService ¶ added in v1.0.3
type ClientsService service
func (*ClientsService) ListAll ¶ added in v1.0.3
func (s *ClientsService) ListAll() ([]ClientResponse, error)
func (*ClientsService) Read ¶ added in v1.0.3
func (s *ClientsService) Read(clientId string) (*ClientResponse, error)
func (*ClientsService) Verify ¶ added in v1.0.3
func (s *ClientsService) Verify(token string) (*ClientResponse, error)
type CreateUpdateJWTTemplate ¶ added in v1.2.0
type CreateUpdateJWTTemplate struct { Name string `json:"name"` Claims map[string]interface{} `json:"claims"` Lifetime *int `json:"lifetime"` AllowedClockSkew *int `json:"allowed_clock_skew"` CustomSigningKey bool `json:"custom_signing_key"` SigningAlgorithm *string `json:"signing_algorithm"` SigningKey *string `json:"signing_key"` }
type DeleteResponse ¶
type EmailAddress ¶
type EmailAddress struct { ID string `json:"id"` Object string `json:"object"` EmailAddress string `json:"email_address"` Verification interface{} `json:"verification"` LinkedTo []IdentificationLink `json:"linked_to"` }
type EmailResponse ¶
type EmailService ¶
type EmailService service
func (*EmailService) Create ¶
func (s *EmailService) Create(email Email) (*EmailResponse, error)
type ErrorResponse ¶ added in v1.0.5
func (*ErrorResponse) Error ¶ added in v1.0.5
func (e *ErrorResponse) Error() string
type IdentificationLink ¶
type InstanceService ¶ added in v1.10.0
type InstanceService service
func (*InstanceService) Update ¶ added in v1.10.0
func (s *InstanceService) Update(params UpdateInstanceParams) error
type JWKSService ¶ added in v1.1.0
type JWKSService service
func (*JWKSService) ListAll ¶ added in v1.1.0
func (s *JWKSService) ListAll() (*JWKS, error)
type JWTTemplate ¶ added in v1.2.0
type JWTTemplate struct { ID string `json:"id"` Object string `json:"object"` Name string `json:"name"` Claims json.RawMessage `json:"claims"` Lifetime int `json:"lifetime"` AllowedClockSkew int `json:"allowed_clock_skew"` CustomSigningKey bool `json:"custom_signing_key"` SigningAlgorithm string `json:"signing_algorithm"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` }
type JWTTemplatesService ¶ added in v1.2.0
type JWTTemplatesService service
func (JWTTemplatesService) Create ¶ added in v1.2.0
func (s JWTTemplatesService) Create(params *CreateUpdateJWTTemplate) (*JWTTemplate, error)
func (JWTTemplatesService) Delete ¶ added in v1.2.0
func (s JWTTemplatesService) Delete(id string) (*DeleteResponse, error)
func (JWTTemplatesService) ListAll ¶ added in v1.2.0
func (s JWTTemplatesService) ListAll() ([]JWTTemplate, error)
func (JWTTemplatesService) Read ¶ added in v1.2.0
func (s JWTTemplatesService) Read(id string) (*JWTTemplate, error)
func (JWTTemplatesService) Update ¶ added in v1.2.0
func (s JWTTemplatesService) Update(id string, params *CreateUpdateJWTTemplate) (*JWTTemplate, error)
type ListAllOrganizationsParams ¶ added in v1.6.0
type ListAllUsersParams ¶ added in v1.0.9
type Organization ¶ added in v1.6.0
type Organization struct { Object string `json:"object"` ID string `json:"id"` Name string `json:"name"` Slug *string `json:"slug"` LogoURL *string `json:"logo_url"` MembersCount int `json:"members_count,omitempty"` PublicMetadata json.RawMessage `json:"public_metadata"` PrivateMetadata json.RawMessage `json:"private_metadata,omitempty"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` }
type OrganizationsResponse ¶ added in v1.6.0
type OrganizationsResponse struct { Data []Organization `json:"data"` TotalCount int64 `json:"total_count"` }
type OrganizationsService ¶ added in v1.6.0
type OrganizationsService service
func (*OrganizationsService) ListAll ¶ added in v1.6.0
func (s *OrganizationsService) ListAll(params ListAllOrganizationsParams) (*OrganizationsResponse, error)
type PhoneNumber ¶
type PhoneNumber struct { ID string `json:"id"` Object string `json:"object"` PhoneNumber string `json:"phone_number"` ReservedForSecondFactor bool `json:"reserved_for_second_factor"` Verification interface{} `json:"verification"` LinkedTo []IdentificationLink `json:"linked_to"` }
type PreviewTemplateRequest ¶ added in v1.2.0
type SMSMessage ¶
type SMSMessageResponse ¶
type SMSMessageResponse struct { Object string `json:"object"` ID string `json:"id"` FromPhoneNumber string `json:"from_phone_number"` ToPhoneNumber *string `json:"to_phone_number,omitempty"` Status string `json:"status"` DeliveredByClerk bool `json:"delivered_by_clerk"` Data json.RawMessage `json:"data"` SMSMessage }
type SMSService ¶
type SMSService service
func (*SMSService) Create ¶
func (s *SMSService) Create(message SMSMessage) (*SMSMessageResponse, error)
type SessionClaims ¶ added in v1.1.0
type SessionClaims struct { jwt.Claims SessionID string `json:"sid"` AuthorizedParty string `json:"azp"` }
func SessionFromContext ¶ added in v1.1.0
func SessionFromContext(ctx context.Context) (*SessionClaims, bool)
SessionFromContext returns the session's (if any) claims, as parsed from the token.
type SessionsService ¶
type SessionsService service
func (*SessionsService) ListAll ¶
func (s *SessionsService) ListAll() ([]Session, error)
type SvixResponse ¶ added in v1.1.0
type SvixResponse struct {
SvixURL string `json:"svix_url"`
}
type Template ¶ added in v1.2.0
type Template struct { Object string `json:"object"` Slug string `json:"slug"` ResourceType string `json:"resource_type"` TemplateType string `json:"template_type"` Name string `json:"name"` Position int `json:"position"` CanRevert bool `json:"can_revert"` CanDelete bool `json:"can_delete"` FromEmailName *string `json:"from_email_name"` DeliveredByClerk bool `json:"delivered_by_clerk"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` }
type TemplateExtended ¶ added in v1.2.0
type TemplatePreview ¶ added in v1.2.0
type TemplatesService ¶ added in v1.2.0
type TemplatesService service
func (*TemplatesService) Delete ¶ added in v1.2.0
func (s *TemplatesService) Delete(templateType, slug string) (*DeleteResponse, error)
Delete deletes a custom user template
func (*TemplatesService) ListAll ¶ added in v1.2.0
func (s *TemplatesService) ListAll(templateType string) ([]Template, error)
func (*TemplatesService) Preview ¶ added in v1.2.0
func (s *TemplatesService) Preview(templateType, slug string, previewTemplateRequest *PreviewTemplateRequest) (*TemplatePreview, error)
Preview returns a rendering of a template with sample data for preview purposes
func (*TemplatesService) Read ¶ added in v1.2.0
func (s *TemplatesService) Read(templateType, slug string) (*TemplateExtended, error)
func (*TemplatesService) Revert ¶ added in v1.2.0
func (s *TemplatesService) Revert(templateType, slug string) (*TemplateExtended, error)
Revert reverts a user template to the corresponding system template
func (*TemplatesService) Upsert ¶ added in v1.2.0
func (s *TemplatesService) Upsert(templateType, slug string, upsertTemplateRequest *UpsertTemplateRequest) (*TemplateExtended, error)
type TokenClaims ¶ added in v1.1.0
type UpdateInstanceParams ¶ added in v1.10.0
type UpdateInstanceParams struct { // TestMode can be used to toggle test mode for this instance. // Defaults to true for development instances. TestMode *bool `json:"test_mode,omitempty"` // HIBP is used to configure whether Clerk should use the // "Have I Been Pawned" service to check passwords against // known security breaches. // By default, this is enabled in all instances. HIBP *bool `json:"hibp,omitempty"` // SupportEmail is the contact email address that will be displayed // on the frontend, in case your instance users need support. // If the empty string is provided, the support email that is currently // configured in the instance will be removed. SupportEmail *string `json:"support_email,omitempty"` }
type UpdateUser ¶
type UpdateUser struct { FirstName *string `json:"first_name,omitempty"` LastName *string `json:"last_name,omitempty"` PrimaryEmailAddressID *string `json:"primary_email_address_id,omitempty"` PrimaryPhoneNumberID *string `json:"primary_phone_number_id,omitempty"` ProfileImage *string `json:"profile_image,omitempty"` Password *string `json:"password,omitempty"` PublicMetadata interface{} `json:"public_metadata,omitempty"` PrivateMetadata interface{} `json:"private_metadata,omitempty"` }
type UpdateUserMetadata ¶ added in v1.9.0
type UpdateUserMetadata struct { PublicMetadata interface{} `json:"public_metadata"` PrivateMetadata interface{} `json:"private_metadata"` UnsafeMetadata interface{} `json:"unsafe_metadata"` }
type UpsertTemplateRequest ¶ added in v1.2.0
type User ¶
type User struct { ID string `json:"id"` Object string `json:"object"` Username *string `json:"username"` FirstName *string `json:"first_name"` LastName *string `json:"last_name"` Gender *string `json:"gender"` Birthday *string `json:"birthday"` ProfileImageURL string `json:"profile_image_url"` PrimaryEmailAddressID *string `json:"primary_email_address_id"` PrimaryPhoneNumberID *string `json:"primary_phone_number_id"` PasswordEnabled bool `json:"password_enabled"` TwoFactorEnabled bool `json:"two_factor_enabled"` EmailAddresses []EmailAddress `json:"email_addresses"` PhoneNumbers []PhoneNumber `json:"phone_numbers"` ExternalAccounts []interface{} `json:"external_accounts"` PublicMetadata interface{} `json:"public_metadata"` PrivateMetadata interface{} `json:"private_metadata"` LastSignInAt *int64 `json:"last_sign_in_at"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` }
type UsersService ¶
type UsersService service
func (*UsersService) Count ¶ added in v1.4.0
func (s *UsersService) Count(params ListAllUsersParams) (*UserCount, error)
func (*UsersService) Delete ¶
func (s *UsersService) Delete(userId string) (*DeleteResponse, error)
func (*UsersService) ListAll ¶
func (s *UsersService) ListAll(params ListAllUsersParams) ([]User, error)
func (*UsersService) Update ¶
func (s *UsersService) Update(userId string, updateRequest *UpdateUser) (*User, error)
func (*UsersService) UpdateMetadata ¶ added in v1.9.0
func (s *UsersService) UpdateMetadata(userId string, updateMetadataRequest *UpdateUserMetadata) (*User, error)
type VerificationService ¶ added in v1.0.3
type VerificationService service
type VerifyTokenOption ¶ added in v1.2.0
type VerifyTokenOption func(*verifyTokenOptions) error
VerifyTokenOption describes a functional parameter for the VerifyToken method
func WithAuthorizedParty ¶ added in v1.2.0
func WithAuthorizedParty(parties ...string) VerifyTokenOption
WithAuthorizedParty allows to set the authorized parties to check against the azp claim of the session token
func WithCustomClaims ¶ added in v1.8.0
func WithCustomClaims(customClaims interface{}) VerifyTokenOption
WithCustomClaims allows to pass a type (e.g. struct), which will be populated with the token claims based on json tags. For this option to work you must pass a pointer.
func WithJWTVerificationKey ¶ added in v1.5.0
func WithJWTVerificationKey(key string) VerifyTokenOption
WithJWTVerificationKey allows to set the JWK to use for verifying tokens without the need to download or cache any JWKs at runtime
func WithLeeway ¶ added in v1.5.0
func WithLeeway(leeway time.Duration) VerifyTokenOption
WithLeeway allows to set a custom leeway that gives some extra time to the token to accomodate for clock skew, etc.
type WebhooksService ¶ added in v1.0.8
type WebhooksService service
func (*WebhooksService) CreateSvix ¶ added in v1.1.0
func (s *WebhooksService) CreateSvix() (*SvixResponse, error)
func (*WebhooksService) DeleteSvix ¶ added in v1.1.0
func (s *WebhooksService) DeleteSvix() error
func (*WebhooksService) RefreshSvixURL ¶ added in v1.1.0
func (s *WebhooksService) RefreshSvixURL() (*SvixResponse, error)