thirdparty

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorCodeInvalidRequest          = "invalid_request"
	ErrorCodeServerError             = "server_error"
	ErrorCodeUserConflict            = "user_conflict"
	ErrorCodeMultipleAccounts        = "multiple_accounts"
	ErrorCodeUnverifiedProviderEmail = "unverified_email"
	ErrorCodeMaxNumberOfAddresses    = "email_maxnum"
)
View Source
const (
	AppleAPIBase       = "https://appleid.apple.com"
	AppleAuthEndpoint  = AppleAPIBase + "/auth/authorize"
	AppleTokenEndpoint = AppleAPIBase + "/auth/token"
	AppleKeysEndpoint  = AppleAPIBase + "/auth/keys"
)
View Source
const (
	GithubAuthBase           = "https://github.com"
	GithubAPIBase            = "https://api.github.com"
	GithubOauthAuthEndpoint  = GithubAuthBase + "/login/oauth/authorize"
	GithubOauthTokenEndpoint = GithubAuthBase + "/login/oauth/access_token"
	GithubUserInfoEndpoint   = GithubAPIBase + "/user"
	GitHubEmailsEndpoint     = GithubAPIBase + "/user/emails"
)
View Source
const (
	GoogleAuthBase           = "https://accounts.google.com"
	GoogleAPIBase            = "https://www.googleapis.com"
	GoogleOauthAuthEndpoint  = GoogleAuthBase + "/o/oauth2/auth"
	GoogleOauthTokenEndpoint = GoogleAuthBase + "/o/oauth2/token"
	GoogleUserInfoEndpoint   = GoogleAPIBase + "/oauth2/v3/userinfo"
)

Variables

View Source
var DefaultAppleScopes = []string{
	"name",
	"email",
}
View Source
var DefaultGitHubScopes = []string{
	"user:email",
}
View Source
var DefaultGoogleScopes = []string{
	"email",
}

Functions

func GenerateState

func GenerateState(config *config.Config, provider string, redirectTo string) ([]byte, error)

func GetErrorUrl

func GetErrorUrl(redirectTo string, err error) string

func IsAllowedRedirect

func IsAllowedRedirect(config config.ThirdParty, redirectTo string) bool

Types

type AccountLinkingResult

type AccountLinkingResult struct {
	Type models.AuditLogType
	User *models.User
}

func LinkAccount

func LinkAccount(tx *pop.Connection, cfg *config.Config, p persistence.Persister, userData *UserData, providerName string) (*AccountLinkingResult, error)

type Claims

type Claims struct {
	// Reserved claims
	Issuer  string  `json:"iss,omitempty" structs:"iss,omitempty"`
	Subject string  `json:"sub,omitempty" structs:"sub,omitempty"`
	Aud     string  `json:"aud,omitempty" structs:"aud,omitempty"`
	Iat     float64 `json:"iat,omitempty" structs:"iat,omitempty"`
	Exp     float64 `json:"exp,omitempty" structs:"exp,omitempty"`

	// Default profile claims
	Name              string `json:"name,omitempty" structs:"name,omitempty"`
	FamilyName        string `json:"family_name,omitempty" structs:"family_name,omitempty"`
	GivenName         string `json:"given_name,omitempty" structs:"given_name,omitempty"`
	MiddleName        string `json:"middle_name,omitempty" structs:"middle_name,omitempty"`
	NickName          string `json:"nickname,omitempty" structs:"nickname,omitempty"`
	PreferredUsername string `json:"preferred_username,omitempty" structs:"preferred_username,omitempty"`
	Profile           string `json:"profile,omitempty" structs:"profile,omitempty"`
	Picture           string `json:"picture,omitempty" structs:"picture,omitempty"`
	Website           string `json:"website,omitempty" structs:"website,omitempty"`
	Gender            string `json:"gender,omitempty" structs:"gender,omitempty"`
	Birthdate         string `json:"birthdate,omitempty" structs:"birthdate,omitempty"`
	ZoneInfo          string `json:"zoneinfo,omitempty" structs:"zoneinfo,omitempty"`
	Locale            string `json:"locale,omitempty" structs:"locale,omitempty"`
	UpdatedAt         string `json:"updated_at,omitempty" structs:"updated_at,omitempty"`
	Email             string `json:"email,omitempty" structs:"email,omitempty"`
	EmailVerified     bool   `json:"email_verified,omitempty" structs:"email_verified,omitempty"`
	Phone             string `json:"phone,omitempty" structs:"phone,omitempty"`
	PhoneVerified     bool   `json:"phone_verified,omitempty" structs:"phone_verified,omitempty"`

	// Custom profile claims that are provider specific
	CustomClaims map[string]interface{} `json:"custom_claims,omitempty" structs:"custom_claims,omitempty"`
}

type Email

type Email struct {
	Email    string
	Verified bool
	Primary  bool
}

type Emails

type Emails []Email

type GithubUser added in v0.6.0

type GithubUser struct {
	ID        int    `json:"id"`
	UserName  string `json:"login"`
	Email     string `json:"email"`
	Name      string `json:"name"`
	AvatarURL string `json:"avatar_url"`
}

type GithubUserEmail added in v0.6.0

type GithubUserEmail struct {
	Email    string `json:"email"`
	Primary  bool   `json:"primary"`
	Verified bool   `json:"verified"`
}

type GoogleUser added in v0.6.0

type GoogleUser struct {
	ID            string `json:"sub"`
	Name          string `json:"name"`
	AvatarURL     string `json:"picture"`
	Email         string `json:"email"`
	EmailVerified bool   `json:"email_verified"`
}

type OAuthProvider

type OAuthProvider interface {
	AuthCodeURL(string, ...oauth2.AuthCodeOption) string
	GetUserData(*oauth2.Token) (*UserData, error)
	GetOAuthToken(string) (*oauth2.Token, error)
	Name() string
}

func GetProvider

func GetProvider(config config.ThirdParty, name string) (OAuthProvider, error)

func NewAppleProvider added in v0.7.0

func NewAppleProvider(config config.ThirdPartyProvider, redirectURL string) (OAuthProvider, error)

func NewGithubProvider

func NewGithubProvider(config config.ThirdPartyProvider, redirectURL string) (OAuthProvider, error)

func NewGoogleProvider

func NewGoogleProvider(config config.ThirdPartyProvider, redirectURL string) (OAuthProvider, error)

NewGoogleProvider creates a Google third party provider.

type State

type State struct {
	Provider   string    `json:"provider"`
	RedirectTo string    `json:"redirect_to"`
	IssuedAt   time.Time `json:"issued_at"`
	ExpiresAt  time.Time `json:"expires_at"`
	Nonce      string    `json:"nonce"`
}

func VerifyState

func VerifyState(config *config.Config, state string, expectedState string) (*State, error)

type ThirdPartyError

type ThirdPartyError struct {
	Code        string
	Description string
	Cause       error
}

func ErrorInvalidRequest

func ErrorInvalidRequest(desc string) *ThirdPartyError

func ErrorMaxNumberOfAddresses

func ErrorMaxNumberOfAddresses(desc string) *ThirdPartyError

func ErrorMultipleAccounts

func ErrorMultipleAccounts(desc string) *ThirdPartyError

func ErrorServer

func ErrorServer(desc string) *ThirdPartyError

func ErrorUnverifiedProviderEmail

func ErrorUnverifiedProviderEmail(desc string) *ThirdPartyError

func ErrorUserConflict

func ErrorUserConflict(desc string) *ThirdPartyError

func NewThirdPartyError

func NewThirdPartyError(code string, description string) *ThirdPartyError

func (*ThirdPartyError) Error

func (e *ThirdPartyError) Error() string

func (*ThirdPartyError) Query

func (e *ThirdPartyError) Query() string

func (*ThirdPartyError) WithCause

func (e *ThirdPartyError) WithCause(cause error) *ThirdPartyError

func (*ThirdPartyError) WithDescription

func (e *ThirdPartyError) WithDescription(description string) *ThirdPartyError

type UserData

type UserData struct {
	Emails   Emails
	Metadata *Claims
}

func (*UserData) ToMap

func (u *UserData) ToMap() map[string]interface{}

Jump to

Keyboard shortcuts

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