firejwt

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

README

FireJWT

Test License

Decode and validate Google Firebase JWT tokens with Ruby and Go.

Usage

Ruby:

require 'firejwt'

# Init a validator
validator = FireJWT::Validator.new 'my-project'

# Decode a token
token = begin
  validator.decode('eyJh...YbQ') # => {'sub' => 'me@example.com', 'aud' => 'my-project'}
rescue JWT::DecodeError
  nil
end

Go:

package main

import (
  "log"

  "github.com/bsm/firejwt"
)

func main() {
  vr, err := firejwt.New("my-project")
  if err != nil {
    log.Fatalln(err)
  }
  defer vr.Stop()

  tk, err := vr.Decode("eyJh...YbQ")
  if err != nil {
    log.Fatalln(err)
  }

  log.Println(tk.Claims) // => {"sub": "me@example.com", "aud": "my-project"}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Claims added in v0.2.0

type Claims struct {
	Name          string           `json:"name,omitempty"`
	Picture       string           `json:"picture,omitempty"`
	UserID        string           `json:"user_id,omitempty"`
	AuthAt        *jwt.NumericDate `json:"auth_time,omitempty"`
	Email         string           `json:"email,omitempty"`
	EmailVerified bool             `json:"email_verified"`
	Firebase      *FirebaseClaim   `json:"firebase,omitempty"`

	jwt.RegisteredClaims
}

Claims are included in the token.

type FirebaseClaim added in v0.2.0

type FirebaseClaim struct {
	SignInProvider string              `json:"sign_in_provider,omitempty"`
	Identities     map[string][]string `json:"identities,omitempty"`
}

FirebaseClaim represents firebase specific claim.

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator validates Firebase JWTs

func New

func New(projectID string) (*Validator, error)

New issues a new Validator with a projectID, a unique identifier for your Firebase project, which can be found in the URL of that project's console.

func (*Validator) Decode

func (v *Validator) Decode(tokenString string) (*Claims, error)

Decode decodes the token

func (*Validator) ExpTime

func (v *Validator) ExpTime() time.Time

ExpTime returns the expiration time.

func (*Validator) Refresh

func (v *Validator) Refresh() error

Refresh retrieves the latest keys.

func (*Validator) Stop

func (v *Validator) Stop()

Stop stops the validator updates.

Jump to

Keyboard shortcuts

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