Documentation
¶
Overview ¶
Package firebase wraps the firebase Admin API for use in a client
Index ¶
- Constants
- func NewOAuthConfig(provider AuthProvider) *oauth2.Config
- type App
- type Auth
- func (auth *Auth) CurrentUser() *User
- func (auth *Auth) SignInWithConsole(ctx context.Context, cfg *oauth2.Config) (*User, *oauth2.Token, error)
- func (auth *Auth) SignInWithConsoleWithIO(ctx context.Context, cfg *oauth2.Config, reader io.Reader, writer io.Writer) (*User, *oauth2.Token, error)
- func (auth *Auth) SignInWithToken(ctx context.Context, token *oauth2.Token) (*User, *oauth2.Token, error)
- func (auth *Auth) SignInWithUser(ctx context.Context, user *User) (token *oauth2.Token, err error)
- func (auth *Auth) SignOut()
- func (auth *Auth) Token() (token *oauth2.Token, err error)
- type AuthOption
- type AuthProvider
- type MemoryUserCache
- type User
- type UserCache
Constants ¶
const ( // DefaultUser represents the default user to be loaded and stored in the // `UserCache`. DefaultUser = "default" )
Variables ¶
This section is empty.
Functions ¶
func NewOAuthConfig ¶
func NewOAuthConfig(provider AuthProvider) *oauth2.Config
NewOAuthConfig creates a new `oauth.Config` for the provided `AuthProvider` based on the built in auth provider configs.
Types ¶
type App ¶
type App struct { APIKey string AuthDomain string DatabaseURL string ProjectID string StorageBucket string MessagingSenderID string AppID string MeasurementID string ClientID string ClientSecret string }
App represents a firebase application
var DefaultApp App
DefaultApp is the default, built in, firebase application
func (*App) NewAuth ¶
func (app *App) NewAuth(opts ...AuthOption) *Auth
NewAuth creates a new authentication client based on the `APIKey`, `ClientID`, and `ClientSecret` in the `App`. You can specify any number of additional AuthOptions when creating the new client.
type Auth ¶
type Auth struct {
// contains filtered or unexported fields
}
Auth handles authenticating users
func (*Auth) CurrentUser ¶
CurrentUser returns the current authenticated user or nil if no user is authenticated.
func (*Auth) SignInWithConsole ¶
func (auth *Auth) SignInWithConsole( ctx context.Context, cfg *oauth2.Config) (*User, *oauth2.Token, error)
SignInWithConsole authenticates the current user by outputting an authentication URL to stdout. The user should copy that URL in to their browser and paste the authentication code back in to the command line.
func (*Auth) SignInWithConsoleWithIO ¶
func (auth *Auth) SignInWithConsoleWithIO( ctx context.Context, cfg *oauth2.Config, reader io.Reader, writer io.Writer) (*User, *oauth2.Token, error)
SignInWithConsoleWithIO performs the same operation as SignInWithConsole, but allows for specifying an input `reader` and output `writer.
func (*Auth) SignInWithToken ¶
func (auth *Auth) SignInWithToken( ctx context.Context, token *oauth2.Token) (*User, *oauth2.Token, error)
SignInWithToken takes an auth token generated by firebase and exchanges it for a refresh token and a user.
func (*Auth) SignInWithUser ¶
SignInWithUser authenticates with a firebase user with a refresh token.
type AuthOption ¶
type AuthOption interface {
Apply(auth *Auth)
}
AuthOption is a generic interface used to apply options when creating a new authentication client.
func WithEmulatorHost ¶
func WithEmulatorHost(emulatorHost string) AuthOption
WithEmulatorHost specifies the authentication emulator host to use in testing. Loading from environment variables is not supported.
func WithUserCache ¶
func WithUserCache(uc UserCache) AuthOption
WithUserCache provides a user cache for the authentication client. This can be used to preserve users across a session.
type AuthProvider ¶
type AuthProvider int
AuthProvider is an enumeration of supported authentication providers.
const ( // GoogleAuthProvider provides support for authenticating with Google GoogleAuthProvider AuthProvider = iota )
type MemoryUserCache ¶
MemoryUserCache implements the `UserCache` interface with an in-memory map.
func (*MemoryUserCache) Delete ¶
func (muc *MemoryUserCache) Delete(userID string)
Delete deletes a user from the cache.
type User ¶
type User struct { UserID string `json:"userId"` EmailVerified bool `json:"emailVerified"` Email string `json:"email"` DisplayName string `json:"displayName"` PhotoURL string `json:"photoUrl"` RefreshToken string `json:"refreshToken"` }
User contains details of a user from Firebase
type UserCache ¶
type UserCache interface { // Get fetches a user from the cache. If no user is found, nil is returned // with a nil error. If a failure occurs an error is returned. Get(string) (*User, error) // Set sets a user in the cache. Set(string, *User) error // Delete deletes a user from the cache. Delete(string) }
UserCache provides an interface for caching authenticated users and their `RefreshToken`. You should avoid backing this with insecure storage like a plaintext file.