clerk

package
v1.1.0-alpha.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2021 License: MIT Imports: 15 Imported by: 24

Documentation

Index

Constants

View Source
const (
	ProdUrl = "https://api.clerk.dev/v1/"

	ClientsUrl       = "clients"
	ClientsVerifyUrl = ClientsUrl + "/verify"
	EmailsUrl        = "emails"
	SessionsUrl      = "sessions"
	SMSUrl           = "sms_messages"
	UsersUrl         = "users"
	WebhooksUrl      = "webhooks"
)
View Source
const (
	ActiveSession = iota
	ActiveSessionClaims
)
View Source
const (
	CookieSession       = "__session"
	QueryParamSessionId = "_clerk_session_id"
)

Variables

This section is empty.

Functions

func RequireSessionV2 added in v1.1.0

func RequireSessionV2(client Client) 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 WithSession(client Client) func(handler http.Handler) http.Handler

func WithSessionV2 added in v1.1.0

func WithSessionV2(client Client) 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 Client

type Client interface {
	NewRequest(method string, url string, body ...interface{}) (*http.Request, error)
	Do(req *http.Request, v interface{}) (*http.Response, error)

	DecodeToken(token string) (*TokenClaims, error)
	VerifyToken(token string) (*SessionClaims, error)

	Clients() *ClientsService
	Emails() *EmailService
	JWKS() *JWKSService
	Sessions() *SessionsService
	SMS() *SMSService
	Users() *UsersService
	Webhooks() *WebhooksService
	Verification() *VerificationService
	Interstitial() ([]byte, error)

	APIKey() string
}

func NewClient

func NewClient(token string) (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

func NewClientWithBaseUrl(token string, baseUrl string) (Client, error)

func NewClientWithCustomHTTP added in v1.0.4

func NewClientWithCustomHTTP(token string, urlStr string, httpClient *http.Client) (Client, error)

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 DeleteResponse

type DeleteResponse struct {
	ID      string `json:"id"`
	Object  string `json:"object"`
	Deleted bool   `json:"deleted"`
}

type Email

type Email struct {
	FromEmailName  string `json:"from_email_name"`
	Subject        string `json:"subject"`
	Body           string `json:"body"`
	EmailAddressID string `json:"email_address_id"`
}

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 EmailResponse struct {
	ID             string  `json:"id"`
	Object         string  `json:"object"`
	Status         string  `json:"status,omitempty"`
	ToEmailAddress *string `json:"to_email_address,omitempty"`
	Email
}

type EmailService

type EmailService service

func (*EmailService) Create

func (s *EmailService) Create(email Email) (*EmailResponse, error)

type Error added in v1.0.5

type Error struct {
	Message     string      `json:"message"`
	LongMessage string      `json:"long_message"`
	Code        string      `json:"code"`
	Meta        interface{} `json:"meta,omitempty"`
}

type ErrorResponse added in v1.0.5

type ErrorResponse struct {
	Response *http.Response
	Errors   []Error `json:"errors"`
}

func (*ErrorResponse) Error added in v1.0.5

func (e *ErrorResponse) Error() string
type IdentificationLink struct {
	IdentType string `json:"type"`
	IdentID   string `json:"id"`
}

type JWKS added in v1.1.0

type JWKS jose.JSONWebKeySet

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 ListAllUsersParams added in v1.0.9

type ListAllUsersParams struct {
	Limit          *int
	Offset         *int
	EmailAddresses []string
	PhoneNumbers   []string
}

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 SMSMessage

type SMSMessage struct {
	Message       string `json:"message"`
	PhoneNumberID string `json:"phone_number_id"`
}

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"`
	SMSMessage
}

type SMSService

type SMSService service

func (*SMSService) Create

func (s *SMSService) Create(message SMSMessage) (*SMSMessageResponse, error)

type Session

type Session struct {
	Object       string `json:"object"`
	ID           string `json:"id"`
	ClientID     string `json:"client_id"`
	UserID       string `json:"user_id"`
	Status       string `json:"status"`
	LastActiveAt int64  `json:"last_active_at"`
	ExpireAt     int64  `json:"expire_at"`
	AbandonAt    int64  `json:"abandon_at"`
}

type SessionClaims added in v1.1.0

type SessionClaims struct {
	jwt.Claims
	SessionID string `json:"sid"`
}

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)

func (*SessionsService) Read

func (s *SessionsService) Read(sessionId string) (*Session, error)

func (*SessionsService) Revoke

func (s *SessionsService) Revoke(sessionId string) (*Session, error)

func (*SessionsService) Verify added in v1.0.3

func (s *SessionsService) Verify(sessionId string, token string) (*Session, error)

type SvixResponse added in v1.1.0

type SvixResponse struct {
	SvixURL string `json:"svix_url"`
}

type TokenClaims added in v1.1.0

type TokenClaims struct {
	jwt.Claims
	Extra map[string]interface{}
}

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 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"`
	CreatedAt             int64          `json:"created_at"`
	UpdatedAt             int64          `json:"updated_at"`
}

type UsersService

type UsersService service

func (*UsersService) Delete

func (s *UsersService) Delete(userId string) (*DeleteResponse, error)

func (*UsersService) ListAll

func (s *UsersService) ListAll(params ListAllUsersParams) ([]User, error)

func (*UsersService) Read

func (s *UsersService) Read(userId string) (*User, error)

func (*UsersService) Update

func (s *UsersService) Update(userId string, updateRequest *UpdateUser) (*User, error)

type VerificationService added in v1.0.3

type VerificationService service

func (*VerificationService) Verify added in v1.0.3

func (s *VerificationService) Verify(req *http.Request) (*Session, error)

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)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL