firebase_id_token 1.2.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -13
- data/firebase_id_token.gemspec +5 -5
- data/lib/firebase_id_token.rb +1 -1
- data/lib/firebase_id_token/certificates.rb +23 -13
- data/lib/firebase_id_token/exceptions/certificates_request_error.rb +1 -1
- data/lib/firebase_id_token/exceptions/certificates_ttl_error.rb +1 -1
- data/lib/firebase_id_token/signature.rb +1 -1
- data/lib/firebase_id_token/version.rb +1 -1
- metadata +32 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 826a39ce30d8e7cf4bebcc40496cf648b2ad05c6
|
4
|
+
data.tar.gz: 1ad801570c7c529577f782c49c283c41ae208c47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8c94b112639ead20b330ce76ca9743a42eea687cf0425ef785cdf2d487dfe04cfd234335426ae2b4d96bda623419f81b8fed99ea6c208c253a1316d57a8054b
|
7
|
+
data.tar.gz: 8a1dac0f03bacfd55078ad51124498e3fc5c5aced06490de25cbfa89ccdd10d322073484bbf67204b60d75507a100da2a92e0a42def260974433c6cd7f955ce7
|
data/README.md
CHANGED
@@ -14,9 +14,9 @@ It also checks the JWT payload parameters as recommended [here](https://firebase
|
|
14
14
|
|
15
15
|
**This gem was developed recently and needs real world feedback.**
|
16
16
|
|
17
|
-
If you are going to use it in production environment, please note that I am still testing it. It has
|
17
|
+
If you are going to use it in a production environment, please note that I am still testing it. It has realistic RSpec examples that use real X509 certificates and signed JWT to perform tests and I can say it's working great. But using it implies in security risks, you should be aware.
|
18
18
|
|
19
|
-
Feel free to open any issue or to [contact me](https://fschuindt.github.io/blog/about/) regarding
|
19
|
+
Feel free to open any issue or to [contact me](https://fschuindt.github.io/blog/about/) regarding its performance.
|
20
20
|
|
21
21
|
## Docs
|
22
22
|
|
@@ -34,7 +34,7 @@ gem install firebase_id_token
|
|
34
34
|
|
35
35
|
or in your Gemfile
|
36
36
|
```
|
37
|
-
gem 'firebase_id_token', '~> 1.
|
37
|
+
gem 'firebase_id_token', '~> 1.3.0'
|
38
38
|
```
|
39
39
|
then
|
40
40
|
```
|
@@ -57,18 +57,21 @@ end
|
|
57
57
|
*If you want to verify signatures from more than one Firebase project, just add more Project IDs to the list.*
|
58
58
|
|
59
59
|
You can also pass a Redis instance to `config` if you are not using Redis defaults.
|
60
|
-
In this case you must have the gem `redis` in your `Gemfile`.
|
60
|
+
In this case, you must have the gem `redis` in your `Gemfile`.
|
61
61
|
```ruby
|
62
62
|
FirebaseIdToken.configure do |config|
|
63
63
|
config.project_ids = ['your-firebase-project-id']
|
64
|
-
|
64
|
+
config.redis = Redis.new(host: '10.0.1.1', port: 6380, db: 15)
|
65
65
|
end
|
66
66
|
```
|
67
67
|
|
68
|
-
Otherwise it will use just `Redis.new` as the instance.
|
68
|
+
Otherwise, it will use just `Redis.new` as the instance.
|
69
69
|
|
70
70
|
## Usage
|
71
71
|
|
72
|
+
You can get a glimpse of it by reading our RSpec output on your machine. It's
|
73
|
+
really helpful. But here is a complete guide:
|
74
|
+
|
72
75
|
### Downloading Certificates
|
73
76
|
|
74
77
|
Before verifying tokens, you need to download Google's x509 certificates.
|
@@ -80,10 +83,10 @@ FirebaseIdToken::Certificates.request
|
|
80
83
|
|
81
84
|
It will download the certificates and save it in Redis, but only if Redis certificates database is empty. To force download and override Redis database, use:
|
82
85
|
```ruby
|
83
|
-
FirebaseIdToken::Certificates.
|
86
|
+
FirebaseIdToken::Certificates.request!
|
84
87
|
```
|
85
88
|
|
86
|
-
Google give us information about the certificates expiration time, it's used to set a Redis TTL (Time-To-Live) when saving it. By doing so, the certificates will be automatically deleted after
|
89
|
+
Google give us information about the certificates expiration time, it's used to set a Redis TTL (Time-To-Live) when saving it. By doing so, the certificates will be automatically deleted after its expiration.
|
87
90
|
|
88
91
|
#### Certificates Info
|
89
92
|
|
@@ -93,13 +96,13 @@ FirebaseIdToken::Certificates.present?
|
|
93
96
|
=> true
|
94
97
|
```
|
95
98
|
|
96
|
-
How many seconds until the
|
99
|
+
How many seconds until the certificate's expiration.
|
97
100
|
```ruby
|
98
101
|
FirebaseIdToken::Certificates.ttl
|
99
102
|
=> 22352
|
100
103
|
```
|
101
104
|
|
102
|
-
Lists all certificates in database.
|
105
|
+
Lists all certificates in a database.
|
103
106
|
```ruby
|
104
107
|
FirebaseIdToken::Certificates.all
|
105
108
|
=> [{"ec8f292sd30224afac5c55540df66d1f999d" => <OpenSSL::X509::Certificate: [...]]
|
@@ -129,8 +132,8 @@ namespace :firebase do
|
|
129
132
|
end
|
130
133
|
|
131
134
|
desc "Request Google's x509 certificates and override Redis"
|
132
|
-
task
|
133
|
-
FirebaseIdToken::Certificates.
|
135
|
+
task request!: :environment do
|
136
|
+
FirebaseIdToken::Certificates.request!
|
134
137
|
end
|
135
138
|
end
|
136
139
|
end
|
@@ -139,7 +142,7 @@ end
|
|
139
142
|
And in your `config/schedule.rb` you might have:
|
140
143
|
```ruby
|
141
144
|
every 1.hour do
|
142
|
-
rake 'firebase:certificates:
|
145
|
+
rake 'firebase:certificates:request!'
|
143
146
|
end
|
144
147
|
```
|
145
148
|
|
data/firebase_id_token.gemspec
CHANGED
@@ -27,12 +27,12 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency 'bundler', '~> 1.14'
|
28
28
|
spec.add_development_dependency 'rake', '~> 10.0'
|
29
29
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
30
|
-
spec.add_development_dependency 'redcarpet', '~> 3.4.0'
|
30
|
+
spec.add_development_dependency 'redcarpet', '~> 3.4', '>= 3.4.0'
|
31
31
|
spec.add_development_dependency 'simplecov', '~> 0.14.1'
|
32
|
-
spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0.0'
|
32
|
+
spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0', '>= 1.0.0'
|
33
33
|
|
34
|
-
spec.
|
35
|
-
spec.
|
34
|
+
spec.add_runtime_dependency 'redis', '~> 3.3', '>= 3.3.3'
|
35
|
+
spec.add_runtime_dependency 'redis-namespace', '~> 1.5', '>= 1.5.3'
|
36
36
|
spec.add_dependency 'httparty', '~> 0.14.0'
|
37
|
-
spec.
|
37
|
+
spec.add_runtime_dependency 'jwt', '~> 1.5', '>= 1.5.6'
|
38
38
|
end
|
data/lib/firebase_id_token.rb
CHANGED
@@ -4,7 +4,7 @@ module FirebaseIdToken
|
|
4
4
|
#
|
5
5
|
# ## Download & Access Certificates
|
6
6
|
#
|
7
|
-
# It describes two ways to download it: {.request} and {.
|
7
|
+
# It describes two ways to download it: {.request} and {.request!}.
|
8
8
|
# The first will only do something when Redis certificates database is empty,
|
9
9
|
# the second one will always request a new download to Google's API and
|
10
10
|
# override the database with the response.
|
@@ -16,7 +16,7 @@ module FirebaseIdToken
|
|
16
16
|
# *To know how many seconds left until the expiration you can use {.ttl}.*
|
17
17
|
#
|
18
18
|
# When comes to accessing it, you can either use {.present?} to check if
|
19
|
-
# there's any data inside Redis certificates database or {.all} to obtain
|
19
|
+
# there's any data inside Redis certificates database or {.all} to obtain an
|
20
20
|
# `Array` of current certificates.
|
21
21
|
#
|
22
22
|
# @example `.request` will only download once
|
@@ -24,10 +24,10 @@ module FirebaseIdToken
|
|
24
24
|
# FirebaseIdToken::Certificates.request # Won't do anything.
|
25
25
|
# FirebaseIdToken::Certificates.request # Won't do anything either.
|
26
26
|
#
|
27
|
-
# @example `.
|
27
|
+
# @example `.request!` will download always
|
28
28
|
# FirebaseIdToken::Certificates.request # Downloads certificates.
|
29
|
-
# FirebaseIdToken::Certificates.
|
30
|
-
# FirebaseIdToken::Certificates.
|
29
|
+
# FirebaseIdToken::Certificates.request! # Downloads certificates.
|
30
|
+
# FirebaseIdToken::Certificates.request! # Downloads certificates.
|
31
31
|
#
|
32
32
|
class Certificates
|
33
33
|
# A Redis instance.
|
@@ -39,15 +39,15 @@ module FirebaseIdToken
|
|
39
39
|
URL = 'https://www.googleapis.com/robot/v1/metadata/x509/'\
|
40
40
|
'securetoken@system.gserviceaccount.com'
|
41
41
|
|
42
|
-
# Calls {.
|
42
|
+
# Calls {.request!} only if there are no certificates on Redis. It will
|
43
43
|
# return `nil` otherwise.
|
44
44
|
#
|
45
45
|
# It will raise {Exceptions::CertificatesRequestError} if the request
|
46
46
|
# fails or {Exceptions::CertificatesTtlError} when Google responds with a
|
47
|
-
# low TTL, check out {.
|
47
|
+
# low TTL, check out {.request!} for more info.
|
48
48
|
#
|
49
49
|
# @return [nil, Hash]
|
50
|
-
# @see Certificates.
|
50
|
+
# @see Certificates.request!
|
51
51
|
def self.request
|
52
52
|
new.request
|
53
53
|
end
|
@@ -62,8 +62,18 @@ module FirebaseIdToken
|
|
62
62
|
# certificate. This is a `SecurityError` and will raise a
|
63
63
|
# {Exceptions::CertificatesTtlError}. You are mostly like to never face it.
|
64
64
|
# @return [Hash]
|
65
|
+
def self.request!
|
66
|
+
new.request!
|
67
|
+
end
|
68
|
+
|
69
|
+
# @deprecated Use only `request!` in favor of Ruby conventions.
|
70
|
+
# It will raise a warning. Kept for compatibility.
|
71
|
+
# @see Certificates.request!
|
65
72
|
def self.request_anyway
|
66
|
-
|
73
|
+
warn 'WARNING: FirebaseIdToken::Certificates.request_anyway is '\
|
74
|
+
'deprecated. Use FirebaseIdToken::Certificates.request! instead.'
|
75
|
+
|
76
|
+
new.request!
|
67
77
|
end
|
68
78
|
|
69
79
|
# Returns `true` if there's certificates data on Redis, `false` otherwise.
|
@@ -75,7 +85,7 @@ module FirebaseIdToken
|
|
75
85
|
! new.local_certs.empty?
|
76
86
|
end
|
77
87
|
|
78
|
-
# Returns
|
88
|
+
# Returns an array of hashes, each hash is a single `{key => value}` pair
|
79
89
|
# containing the certificate KID `String` as key and a
|
80
90
|
# `OpenSSL::X509::Certificate` object of the respective certificate as
|
81
91
|
# value. Returns a empty `Array` when there's no certificates data on
|
@@ -130,11 +140,11 @@ module FirebaseIdToken
|
|
130
140
|
|
131
141
|
# @see Certificates.request
|
132
142
|
def request
|
133
|
-
|
143
|
+
request! if @local_certs.empty?
|
134
144
|
end
|
135
145
|
|
136
|
-
# @see Certificates.
|
137
|
-
def
|
146
|
+
# @see Certificates.request!
|
147
|
+
def request!
|
138
148
|
@request = HTTParty.get URL
|
139
149
|
code = @request.code
|
140
150
|
if code == 200
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module FirebaseIdToken
|
2
2
|
module Exceptions
|
3
3
|
# @see FirebaseIdToken::Certificates.request
|
4
|
-
# @see FirebaseIdToken::Certificates.
|
4
|
+
# @see FirebaseIdToken::Certificates.request!
|
5
5
|
class CertificatesRequestError < StandardError
|
6
6
|
def initialize(code)
|
7
7
|
super "#{code} HTTP status when requesting Google's certificates."
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module FirebaseIdToken
|
2
2
|
module Exceptions
|
3
3
|
# @see FirebaseIdToken::Certificates.request
|
4
|
-
# @see FirebaseIdToken::Certificates.
|
4
|
+
# @see FirebaseIdToken::Certificates.request!
|
5
5
|
class CertificatesTtlError < StandardError
|
6
6
|
def initialize(message = "Google's x509 certificates has a low TTL.")
|
7
7
|
super message
|
@@ -37,7 +37,7 @@ module FirebaseIdToken
|
|
37
37
|
#
|
38
38
|
# It will also return `nil` when it fails in checking if all the required
|
39
39
|
# JWT fields are valid, as recommended [here](https://goo.gl/yOrZZX) by
|
40
|
-
# Firebase
|
40
|
+
# Firebase official documentation.
|
41
41
|
#
|
42
42
|
# Note that it will raise a {Exceptions::NoCertificatesError} if the Redis
|
43
43
|
# certificates database is empty. Ensure to call {Certificates.request}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: firebase_id_token
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fernando Schuindt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -57,6 +57,9 @@ dependencies:
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.4'
|
62
|
+
- - ">="
|
60
63
|
- !ruby/object:Gem::Version
|
61
64
|
version: 3.4.0
|
62
65
|
type: :development
|
@@ -64,6 +67,9 @@ dependencies:
|
|
64
67
|
version_requirements: !ruby/object:Gem::Requirement
|
65
68
|
requirements:
|
66
69
|
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '3.4'
|
72
|
+
- - ">="
|
67
73
|
- !ruby/object:Gem::Version
|
68
74
|
version: 3.4.0
|
69
75
|
- !ruby/object:Gem::Dependency
|
@@ -85,6 +91,9 @@ dependencies:
|
|
85
91
|
requirement: !ruby/object:Gem::Requirement
|
86
92
|
requirements:
|
87
93
|
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '1.0'
|
96
|
+
- - ">="
|
88
97
|
- !ruby/object:Gem::Version
|
89
98
|
version: 1.0.0
|
90
99
|
type: :development
|
@@ -92,6 +101,9 @@ dependencies:
|
|
92
101
|
version_requirements: !ruby/object:Gem::Requirement
|
93
102
|
requirements:
|
94
103
|
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '1.0'
|
106
|
+
- - ">="
|
95
107
|
- !ruby/object:Gem::Version
|
96
108
|
version: 1.0.0
|
97
109
|
- !ruby/object:Gem::Dependency
|
@@ -99,6 +111,9 @@ dependencies:
|
|
99
111
|
requirement: !ruby/object:Gem::Requirement
|
100
112
|
requirements:
|
101
113
|
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '3.3'
|
116
|
+
- - ">="
|
102
117
|
- !ruby/object:Gem::Version
|
103
118
|
version: 3.3.3
|
104
119
|
type: :runtime
|
@@ -106,6 +121,9 @@ dependencies:
|
|
106
121
|
version_requirements: !ruby/object:Gem::Requirement
|
107
122
|
requirements:
|
108
123
|
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '3.3'
|
126
|
+
- - ">="
|
109
127
|
- !ruby/object:Gem::Version
|
110
128
|
version: 3.3.3
|
111
129
|
- !ruby/object:Gem::Dependency
|
@@ -113,6 +131,9 @@ dependencies:
|
|
113
131
|
requirement: !ruby/object:Gem::Requirement
|
114
132
|
requirements:
|
115
133
|
- - "~>"
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '1.5'
|
136
|
+
- - ">="
|
116
137
|
- !ruby/object:Gem::Version
|
117
138
|
version: 1.5.3
|
118
139
|
type: :runtime
|
@@ -120,6 +141,9 @@ dependencies:
|
|
120
141
|
version_requirements: !ruby/object:Gem::Requirement
|
121
142
|
requirements:
|
122
143
|
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '1.5'
|
146
|
+
- - ">="
|
123
147
|
- !ruby/object:Gem::Version
|
124
148
|
version: 1.5.3
|
125
149
|
- !ruby/object:Gem::Dependency
|
@@ -141,6 +165,9 @@ dependencies:
|
|
141
165
|
requirement: !ruby/object:Gem::Requirement
|
142
166
|
requirements:
|
143
167
|
- - "~>"
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '1.5'
|
170
|
+
- - ">="
|
144
171
|
- !ruby/object:Gem::Version
|
145
172
|
version: 1.5.6
|
146
173
|
type: :runtime
|
@@ -148,6 +175,9 @@ dependencies:
|
|
148
175
|
version_requirements: !ruby/object:Gem::Requirement
|
149
176
|
requirements:
|
150
177
|
- - "~>"
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '1.5'
|
180
|
+
- - ">="
|
151
181
|
- !ruby/object:Gem::Version
|
152
182
|
version: 1.5.6
|
153
183
|
description: A Ruby gem to verify the signature of Firebase ID Tokens. It uses Redis
|