Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: the Auth and User structs are now public #128

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ type MagicLinkOptions struct {
TTL int
}

type auth struct {
type Auth struct {
appID string
client *ClientWithResponses
jwksCacheSet jwk.Set
}

func newAuth(appID string, client *ClientWithResponses) (*auth, error) {
func newAuth(appID string, client *ClientWithResponses) (*Auth, error) {
ctx := context.Background()

url := fmt.Sprintf("https://auth.passage.id/v1/apps/%v/.well-known/jwks.json", appID)
Expand All @@ -37,15 +37,15 @@ func newAuth(appID string, client *ClientWithResponses) (*auth, error) {
return nil, fmt.Errorf("failed to fetch JWKS: %w", err)
}

return &auth{
return &Auth{
appID: appID,
client: client,
jwksCacheSet: jwk.NewCachedSet(cache, url),
}, nil
}

// CreateMagicLink creates a Magic Link for your app using an email address.
func (a *auth) CreateMagicLinkWithEmail(
func (a *Auth) CreateMagicLinkWithEmail(
email string,
magicLinkType MagicLinkType,
send bool,
Expand All @@ -62,7 +62,7 @@ func (a *auth) CreateMagicLinkWithEmail(
}

// CreateMagicLink creates a Magic Link for your app using an E164-formatted phone number.
func (a *auth) CreateMagicLinkWithPhone(
func (a *Auth) CreateMagicLinkWithPhone(
phone string,
magicLinkType MagicLinkType,
send bool,
Expand All @@ -79,7 +79,7 @@ func (a *auth) CreateMagicLinkWithPhone(
}

// CreateMagicLink creates a Magic Link for your app using a Passage user ID.
func (a *auth) CreateMagicLinkWithUser(
func (a *Auth) CreateMagicLinkWithUser(
userID string,
channel ChannelType,
magicLinkType MagicLinkType,
Expand All @@ -97,7 +97,7 @@ func (a *auth) CreateMagicLinkWithUser(
}

// ValidateJWT validates the JWT and returns the user ID.
func (a *auth) ValidateJWT(jwt string) (string, error) {
func (a *Auth) ValidateJWT(jwt string) (string, error) {
if jwt == "" {
return "", errors.New("jwt is required.")
}
Expand All @@ -124,7 +124,7 @@ func (a *auth) ValidateJWT(jwt string) (string, error) {
return userID, nil
}

func (a *auth) createMagicLink(args magicLinkArgs, opts *MagicLinkOptions) (*MagicLink, error) {
func (a *Auth) createMagicLink(args magicLinkArgs, opts *MagicLinkOptions) (*MagicLink, error) {
if opts != nil {
if err := validateLanguage(opts.Language); err != nil {
return nil, err
Expand All @@ -148,7 +148,7 @@ func (a *auth) createMagicLink(args magicLinkArgs, opts *MagicLinkOptions) (*Mag
return nil, errorFromResponse(res.Body, res.StatusCode())
}

func (a *auth) getPublicKey(token *jwt.Token) (interface{}, error) {
func (a *Auth) getPublicKey(token *jwt.Token) (interface{}, error) {
keyID, ok := token.Header["kid"].(string)
if !ok {
return nil, errors.New("failed to find kid in JWT header")
Expand Down
4 changes: 2 additions & 2 deletions passage.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

// Passage is the main struct for the Passage SDK.
type Passage struct {
Auth *auth
User *user
Auth *Auth
User *User
}

// New creates a new Passage instance.
Expand Down
26 changes: 13 additions & 13 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import (
"strings"
)

type user struct {
type User struct {
appID string
client *ClientWithResponses
}

func newUser(appID string, client *ClientWithResponses) *user {
return &user{
func newUser(appID string, client *ClientWithResponses) *User {
return &User{
appID: appID,
client: client,
}
}

// Get retrieves a user's object using their user ID.
func (u *user) Get(userID string) (*PassageUser, error) {
func (u *User) Get(userID string) (*PassageUser, error) {
if userID == "" {
return nil, errors.New("userID is required.")
}
Expand All @@ -38,7 +38,7 @@ func (u *user) Get(userID string) (*PassageUser, error) {
}

// GetByIdentifier retrieves a user's object using their user identifier.
func (u *user) GetByIdentifier(identifier string) (*PassageUser, error) {
func (u *User) GetByIdentifier(identifier string) (*PassageUser, error) {
if identifier == "" {
return nil, errors.New("identifier is required.")
}
Expand Down Expand Up @@ -76,7 +76,7 @@ func (u *user) GetByIdentifier(identifier string) (*PassageUser, error) {
}

// Activate activates a user using their user ID.
func (u *user) Activate(userID string) (*PassageUser, error) {
func (u *User) Activate(userID string) (*PassageUser, error) {
if userID == "" {
return nil, errors.New("userID is required.")
}
Expand All @@ -94,7 +94,7 @@ func (u *user) Activate(userID string) (*PassageUser, error) {
}

// Deactivate deactivates a user using their user ID.
func (u *user) Deactivate(userID string) (*PassageUser, error) {
func (u *User) Deactivate(userID string) (*PassageUser, error) {
if userID == "" {
return nil, errors.New("userID is required.")
}
Expand All @@ -112,7 +112,7 @@ func (u *user) Deactivate(userID string) (*PassageUser, error) {
}

// Update updates a user.
func (u *user) Update(userID string, options UpdateUserOptions) (*PassageUser, error) {
func (u *User) Update(userID string, options UpdateUserOptions) (*PassageUser, error) {
if userID == "" {
return nil, errors.New("userID is required.")
}
Expand All @@ -130,7 +130,7 @@ func (u *user) Update(userID string, options UpdateUserOptions) (*PassageUser, e
}

// Create creates a user.
func (u *user) Create(args CreateUserArgs) (*PassageUser, error) {
func (u *User) Create(args CreateUserArgs) (*PassageUser, error) {
if args.Email == "" && args.Phone == "" {
return nil, errors.New("At least one of args.Email or args.Phone is required.")
}
Expand All @@ -148,7 +148,7 @@ func (u *user) Create(args CreateUserArgs) (*PassageUser, error) {
}

// Delete deletes a user using their user ID.
func (u *user) Delete(userID string) error {
func (u *User) Delete(userID string) error {
if userID == "" {
return errors.New("userID is required.")
}
Expand All @@ -166,7 +166,7 @@ func (u *user) Delete(userID string) error {
}

// ListDevices retrieves a user's webauthn devices using their user ID.
func (u *user) ListDevices(userID string) ([]WebAuthnDevices, error) {
func (u *User) ListDevices(userID string) ([]WebAuthnDevices, error) {
if userID == "" {
return nil, errors.New("userID is required.")
}
Expand All @@ -184,7 +184,7 @@ func (u *user) ListDevices(userID string) ([]WebAuthnDevices, error) {
}

// RevokeDevice revokes user's webauthn device using their user ID and the device ID.
func (u *user) RevokeDevice(userID string, deviceID string) error {
func (u *User) RevokeDevice(userID string, deviceID string) error {
if userID == "" {
return errors.New("userID is required.")
}
Expand All @@ -206,7 +206,7 @@ func (u *user) RevokeDevice(userID string, deviceID string) error {
}

// RevokeRefreshTokens revokes all of a user's Refresh Tokens using their User ID.
func (u *user) RevokeRefreshTokens(userID string) error {
func (u *User) RevokeRefreshTokens(userID string) error {
if userID == "" {
return errors.New("userID is required.")
}
Expand Down
Loading