Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ClientCallbackURL is where the frontend will receive the OAuth result. ClientCallbackURL string // ProviderMap maps provider names to their OAuthProvider implementation. ProviderMap = map[string]OAuthProvider{} // UserDB is required to get user data from the database. UserDB UserDatabase )
Dependencies of the core.
View Source
var ( // ErrProviderNotFound is returned when the required provider is not supported. ErrProviderNotFound = errors.New("provider not found") // ErrUserNotFound is returned when the required user document is not present in the database. ErrUserNotFound = errors.New("user not found") )
Functions ¶
func OAuthCallback ¶
func OAuthCallback(ctx context.Context, provider string, code string, writer http.ResponseWriter) error
OAuthCallback handles the callback received from the provider.
func OAuthRedirect ¶
OAuthRedirect redirects the caller to the specified provider's auth page.
Types ¶
type OAuthProvider ¶
type OAuthProvider interface {
// Name provides the name of the provider.
Name() string
// GetRedirectURL returns the URL to the auth page of the provider.
GetRedirectURL(ctx context.Context) string
// Code2Token converts the auth code to identity token.
Code2Token(ctx context.Context, code string) (string, error)
// Token2UserInfo converts the identity token into the user's info.
Token2UserInfo(ctx context.Context, token string) (*UserDoc, error)
}
OAuthProvider represents a generic OAuth provider.
type UserDatabase ¶
type UserDatabase interface {
// SetUser upserts the user's info in the database.
SetUser(ctx context.Context, doc *UserDoc) error
// GetUserInfo fetches the user info for the provided userID.
GetUser(ctx context.Context, userID string) (*UserDoc, error)
}
UserDatabase represents the database layer for user information.
type UserDoc ¶
type UserDoc struct {
ID string `json:"_id" bson:"_id"`
Email string `json:"email" bson:"email"`
FirstName string `json:"first_name" bson:"first_name"`
LastName string `json:"last_name" bson:"last_name"`
PictureLink string `json:"picture_link" bson:"picture_link"`
}
UserDoc is the schema of the user document as saved in the database.
Click to show internal directories.
Click to hide internal directories.