Skip to content

bsm/firejwt

Repository files navigation

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' => '[email protected]', '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": "[email protected]", "aud": "my-project"}
}