auth

package module
v0.0.0-...-ca7e696 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2017 License: MIT Imports: 16 Imported by: 0

README

Firebase Auth

GoDoc Go Report Card

Firebase Auth library

Install

$ go get -v -u github.com/k2wanko/firebase-auth

Usage


import(
    ...
    'github.com/k2wanko/firebase-auth'
)

func handle(w http.ResponseWriter, r *http.Request) {
    ctx := appengine.NewContext(r)
    tokStr, err := auth.CreateCustomToken(ctx, "some-uid", map[string]interface{}{
        "premium_account": true,
    })
    if err != nil {
        panic(err)
    }

    tok, err := auth.VerifyIDToken(c, tokStr)
}

Documentation

Index

Constants

View Source
const (
	// ClientCertURL is URL containing the public keys for the Google certs
	ClientCertURL = "https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com"

	// FirebaseAudienceURL is Audience to use for Firebase Auth Custom tokens
	FirebaseAudienceURL = "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit"
)

Variables

View Source
var (
	// BlackListedClaims is List of blacklisted claims which cannot be provided when creating a custom token
	// FYI: https://firebase.google.com/docs/auth/server/create-custom-tokens
	BlackListedClaims = []string{
		"acr", "amr", "at_hash", "aud", "auth_time", "azp",
		"cnf", "c_hash", "exp", "iat", "iss", "jti", "nbf", "nonce",
	}
)

Functions

func CreateCustomToken

func CreateCustomToken(c context.Context, uid string, developerClaims interface{}) (string, error)

CreateCustomToken is Creates a new Firebase Auth Custom token.

func VerifyIDToken

func VerifyIDToken(c context.Context, idToken string) (*jwt.Token, error)

VerifyIDToken is Verifies the format and signature of a Firebase Auth ID token

func WithServiceAccount

func WithServiceAccount(c context.Context, sa *ServiceAccount) context.Context

WithServiceAccount returns copy parent context and associates it with ServiceAccount.

Types

type AppEngineSigningMethod

type AppEngineSigningMethod struct{}

AppEngineSigningMethod is built-in AppEngine signing method

func (*AppEngineSigningMethod) Alg

func (s *AppEngineSigningMethod) Alg() string

Alg is algorithm name

func (*AppEngineSigningMethod) Sign

func (s *AppEngineSigningMethod) Sign(signingString string, key interface{}) (string, error)

Sign is Implment SigningMethod#Sign

func (*AppEngineSigningMethod) Verify

func (s *AppEngineSigningMethod) Verify(signingString, signature string, key interface{}) error

Verify is Implment SigningMethod#Verify

type FirebaseClaims

type FirebaseClaims struct {
	UID           string      `json:"uid,omitempty"`
	UserIDStr     string      `json:"user_id,omitempty"`
	Email         string      `json:"email,omitempty"`
	EmailVerified bool        `json:"email_verified,omitempty"`
	Claims        interface{} `json:"claims,omitempty"`
	Firebase      *struct {
		SignInProvider string              `json:"sign_in_provider,omitempty"`
		Identities     map[string][]string `json:"identities,omitempty"`
	} `json:"firebase,omitempty"`

	*jwt.StandardClaims
}

FirebaseClaims is Token struct

func (*FirebaseClaims) UserID

func (f *FirebaseClaims) UserID() string

UserID is Firebase UserID from Token

type ServiceAccount

type ServiceAccount struct {
	Type                    string `json:"type,omitempty"`
	ProjectID               string `json:"project_id,omitempty"`
	PrivateKeyID            string `json:"private_key_id,omitempty"`
	PrivateKey              string `json:"private_key,omitempty"`
	ClientEmail             string `json:"client_email,omitempty"`
	ClientID                string `json:"client_id,omitempty"`
	AuthURI                 string `json:"auth_uri,omitempty"`
	TokenURI                string `json:"token_uri,omitempty"`
	AuthProviderX509CertURL string `json:"auth_provider_x509_cert_url,omitempty"`
	ClientX509CertURL       string `json:"client_x509_cert_url,omitempty"`
}

Jump to

Keyboard shortcuts

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