firebase_token_authentication 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46b815bea1125de46657346311dcebb824599311002a855b01c1f547e3fa7ebc
4
- data.tar.gz: cd5a9fb3d6cae10429b344426909f143706a1c9d607a8b9b69d4d9dcc066e439
3
+ metadata.gz: 5a55c30f4e1bca8c32eba0ef7d317e81e6ac99432d2f5f60f851e2a19514e629
4
+ data.tar.gz: eee31410315e81f0a4579684b6e6eabe12d6ec9d891b792752398dadb1456811
5
5
  SHA512:
6
- metadata.gz: 3be745baa590030ed8de336a11879a3f99afbe7da023af3a8242c3a4370b814edd36f36c2e0aa060535100158aaadd20c1117a287b72682bd21fb837f6e96f37
7
- data.tar.gz: b29b18965dfa204ba17f6f32e88254c1a8dee1b049723bf8836977367af32f10a5e65148f16bbf6250fe1b2f2b591c6e7b1d357ac0048d9cbea6e58ee2f271e4
6
+ metadata.gz: 9cb923b4c7e9a0444231e6a81f37ba854b1b08f14d23474aead6f8793eb2f77a24b0f2425c249242f6ef175c3532d73e7887e76fdc10958098c53438fd9cb474
7
+ data.tar.gz: 6625152e878d4c580e1fb05a319c7534b6d4b62736fd8ba64b255aca185833f541fe59edabed3bc7ef516eb979352cf2b90dd32677dd98e5b44509401cb07765
data/README.md CHANGED
@@ -1,15 +1,17 @@
1
- # FirebaseAuth
1
+ # Firebase Token Authentication
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/firebase_auth`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ A light weight Firebase access token validator which utilizes HTTP caching to reduce network traffic when validating against Google's X509 Certificates.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ The goal of this project was to create a reusable, light weight, non-rails dependent library to validate [Firebase Authentication](https://firebase.google.com/docs/auth) access tokens which could utilize an efficient cache without a required external dependency, like Redis. Moreover I wanted a solution flexible enough to host on Heroku which could safely survive dyno refreshes. After a dyno refreshes, on each dyno, the first call to fetch the Google X509 certs will go over the network, but from then on be cached.
6
+
7
+ Underneath we are using the [ruby-jwt](https://github.com/jwt/ruby-jwt) gem to decode the access token. If the token does not decode properly it will raise an exception. We wrap the exception inside a `FirebaseTokenAuthentication::Error` to help differentiate between your application's own JWT implementation.
6
8
 
7
9
  ## Installation
8
10
 
9
11
  Add this line to your application's Gemfile:
10
12
 
11
13
  ```ruby
12
- gem 'firebase_auth'
14
+ gem 'firebase_token_authentication'
13
15
  ```
14
16
 
15
17
  And then execute:
@@ -18,21 +20,89 @@ And then execute:
18
20
 
19
21
  Or install it yourself as:
20
22
 
21
- $ gem install firebase_auth
23
+ $ gem install firebase_token_authentication
22
24
 
23
25
  ## Usage
24
26
 
25
- TODO: Write usage instructions here
27
+ ### Configuration
28
+
29
+ ```ruby
30
+ # config/initializers/firebase_token_authentication.rb
31
+
32
+ FirebaseTokenAuthentication.configure do |config|
33
+ # Your Firebase Project ID
34
+ config.firebase_project_id = ENV['firebase_project_id']
35
+
36
+ # An optional cache store to persist X509 Certificates
37
+ config.cache_store = CacheStore.new
38
+
39
+ # An optional logger hook to view cache status
40
+ config.logger = Logger.new(STDOUT)
41
+ end
42
+ ```
43
+
44
+ ### Cache Store
45
+
46
+ The gem uses [Faraday](https://github.com/lostisland/faraday) with the [faraday-http-cache](https://github.com/sourcelevel/faraday-http-cache) middleware gem to manage the cache.
47
+
48
+ Any cache object that responds to `write(key, value)`, `read(key)`, and `delete(key)` is a valid cache store. To that extent you could roll your own cache store quite easily.
49
+
50
+ A very rough, but easy to understand, example with a plain ol' ruby object:
51
+
52
+ ```ruby
53
+ class CacheStore
54
+ def write(key, value)
55
+ store[key] = value
56
+ end
57
+
58
+ def read(key)
59
+ store[key]
60
+ end
61
+
62
+ def delete(key)
63
+ store.delete(key)
64
+ store
65
+ end
66
+
67
+ def store
68
+ @store ||= {}
69
+ end
70
+ end
71
+ ```
72
+
73
+ #### Rails Cache
74
+
75
+ The [Rails.cache](https://guides.rubyonrails.org/caching_with_rails.html) is a valid cache store. As a reminder though it is disabled in Development and Test environments and has many different config options. I recommend you review [the docs](https://guides.rubyonrails.org/caching_with_rails.html).
76
+
77
+ ### Logger
78
+
79
+ The `config.logger` allows you to view the status of the cache. An example of a log:
80
+
81
+ `HTTP Cache: [GET /robot/v1/metadata/x509/securetoken@system.gserviceaccount.com] fresh`
82
+
83
+ Pulled directly from the [faraday-http-cache](https://github.com/sourcelevel/faraday-http-cache) docs, the keys represent the following:
84
+
85
+ - `:unacceptable` means that the request did not go through the cache at all.
86
+ - `:miss` means that no cached response could be found.
87
+ - `:invalid` means that the cached response could not be validated against the server.
88
+ - `:valid` means that the cached response could be validated against the server.
89
+ - `:fresh` means that the cached response was still fresh and could be returned without even calling the server.
26
90
 
27
91
  ## Development
28
92
 
93
+ ### TODOs
94
+
95
+ - [ ] Complete the test suite
96
+ - [ ] Class and method documentation
97
+ - [ ] Add support for non shared cache [RFC 2616 Shared and Non-Shared Caches](https://datatracker.ietf.org/doc/html/rfc2616#section-13.7) which seems simple [with this config](https://github.com/sourcelevel/faraday-http-cache#shared-vs-non-shared-caches).
98
+
29
99
  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.
30
100
 
31
101
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
102
 
33
103
  ## Contributing
34
104
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/firebase_auth. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/firebase_auth/blob/main/CODE_OF_CONDUCT.md).
105
+ Bug reports and pull requests are welcome on GitHub at https://github.com/alphabites/firebase_auth. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/alphabites/firebase_auth/blob/main/CODE_OF_CONDUCT.md).
36
106
 
37
107
  ## License
38
108
 
@@ -21,14 +21,14 @@ module FirebaseTokenAuthentication
21
21
 
22
22
  def verify
23
23
  decode(key: certificate.find(key_id))
24
- rescue StandardError => e
25
- raise FirebaseTokenAuthentication::Error, e.message
26
24
  end
27
25
 
28
26
  private
29
27
 
30
28
  def decode(key: nil, verify_key: true)
31
29
  JWT.decode(firebase_token, key&.public_key, verify_key, decode_options)
30
+ rescue StandardError => e
31
+ raise FirebaseTokenAuthentication::Error, e.message
32
32
  end
33
33
 
34
34
  def decode_options
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FirebaseTokenAuthentication
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firebase_token_authentication
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Fuller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-18 00:00:00.000000000 Z
11
+ date: 2022-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -94,7 +94,8 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- description:
97
+ description: A light weight Firebase access token validator whichutilizes HTTP caching
98
+ to reduce network traffic whenvalidating against Google's X509 Certificates.
98
99
  email:
99
100
  - nfuller52@gmail.com
100
101
  executables: []
@@ -106,7 +107,6 @@ files:
106
107
  - CHANGELOG.md
107
108
  - CODE_OF_CONDUCT.md
108
109
  - Gemfile
109
- - Gemfile.lock
110
110
  - LICENSE.txt
111
111
  - README.md
112
112
  - Rakefile
@@ -142,5 +142,5 @@ requirements: []
142
142
  rubygems_version: 3.3.3
143
143
  signing_key:
144
144
  specification_version: 4
145
- summary: Simple tool for verifying Firebase Authentication JWT tokens.
145
+ summary: Simple tool for verifying Firebase JWT access tokens.
146
146
  test_files: []
data/Gemfile.lock DELETED
@@ -1,82 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- firebase_token_authentication (0.1.1)
5
- faraday
6
- faraday-http-cache
7
- jwt
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- ast (2.4.2)
13
- debug (1.4.0)
14
- irb (>= 1.3.6)
15
- reline (>= 0.2.7)
16
- diff-lcs (1.5.0)
17
- faraday (2.1.0)
18
- faraday-net_http (~> 2.0)
19
- ruby2_keywords (>= 0.0.4)
20
- faraday-http-cache (2.2.0)
21
- faraday (>= 0.8)
22
- faraday-net_http (2.0.1)
23
- io-console (0.5.11)
24
- irb (1.4.1)
25
- reline (>= 0.3.0)
26
- jwt (2.3.0)
27
- parallel (1.21.0)
28
- parser (3.1.0.0)
29
- ast (~> 2.4.1)
30
- rainbow (3.1.1)
31
- rake (13.0.6)
32
- regexp_parser (2.2.0)
33
- reline (0.3.1)
34
- io-console (~> 0.5)
35
- rexml (3.2.5)
36
- rspec (3.10.0)
37
- rspec-core (~> 3.10.0)
38
- rspec-expectations (~> 3.10.0)
39
- rspec-mocks (~> 3.10.0)
40
- rspec-core (3.10.1)
41
- rspec-support (~> 3.10.0)
42
- rspec-expectations (3.10.2)
43
- diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.10.0)
45
- rspec-mocks (3.10.2)
46
- diff-lcs (>= 1.2.0, < 2.0)
47
- rspec-support (~> 3.10.0)
48
- rspec-support (3.10.3)
49
- rubocop (1.24.1)
50
- parallel (~> 1.10)
51
- parser (>= 3.0.0.0)
52
- rainbow (>= 2.2.2, < 4.0)
53
- regexp_parser (>= 1.8, < 3.0)
54
- rexml
55
- rubocop-ast (>= 1.15.1, < 2.0)
56
- ruby-progressbar (~> 1.7)
57
- unicode-display_width (>= 1.4.0, < 3.0)
58
- rubocop-ast (1.15.1)
59
- parser (>= 3.0.1.1)
60
- rubocop-rake (0.6.0)
61
- rubocop (~> 1.0)
62
- rubocop-rspec (2.7.0)
63
- rubocop (~> 1.19)
64
- ruby-progressbar (1.11.0)
65
- ruby2_keywords (0.0.5)
66
- unicode-display_width (2.1.0)
67
-
68
- PLATFORMS
69
- arm64-darwin-20
70
- x86_64-linux
71
-
72
- DEPENDENCIES
73
- debug
74
- firebase_token_authentication!
75
- rake (~> 13.0)
76
- rspec (~> 3.0)
77
- rubocop (~> 1.21)
78
- rubocop-rake
79
- rubocop-rspec
80
-
81
- BUNDLED WITH
82
- 2.3.5