Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 77 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,82 @@
# Firebase::Auth::IDTokenKeeper

## Description

firebase-auth-id_token_keeper provides various functions such as verification of jwt published by [firebase authorication](https://firebase.google.com/docs/auth).

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'firebase-auth-id_token_keeper'
```

And then execute:

$ bundle

Or install it yourself as:

$ gem install firebase-auth-id_token_keeper

## Prerequisites

You need to set firebase projrct info

For example:

```ruby
Firebase::Auth::IDTokenKeeper.configure do |config|
config.firebase_project_id = 'firebase_project_id'
end
```

For more information about Firebase project-id, please see below.

https://firebase.google.com/docs/projects/learn-more?hl=en#project-id

## Usage

When you receive the request header follows:

```
"Authorization: Bearer [firebase_published_jwt]”
```

Should be added ApplicationController as follows:

```ruby
# frozen_string_literal: true

class ApplicationController < V2::ApplicationController
protect_from_forgery

class NoAuthorizationHeaderError < StandardError; end
class NoJWTError < StandardError; end

protected

def verified_id_token
id_token.verified_id_token
end

def id_token
Firebase::Auth::IDTokenKeeper::IDToken.new(jwt)
end

def jwt
authorization_header.to_s.split(' ')[1].presence || raise(NoJWTError)
end

def authorization_header
request.headers['Authorization'].presence || raise(NoAuthorizationHeaderError)
end
end
```

By doing so, You can use `verified_id_token` on all Controllers that inherit this ApplicationController

## Errors

### Response body
Expand Down Expand Up @@ -87,26 +164,6 @@ require 'support/firebase_auth_id_token_keeper'

Now, we can decode test ID Token which is generated via `Firebase::Auth::IDTokenKeeper::Testing.generate_test_id_token` method in `Firebase::Auth::IDTokenKeeper::IDToken#verified_id_token` method.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'firebase-auth-id_token_keeper'
```

And then execute:

$ bundle

Or install it yourself as:

$ gem install firebase-auth-id_token_keeper

## Usage

TODO: Write usage instructions here

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
Expand Down