firebase-auth-id_token 0.1.0
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +0 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +58 -0
- data/LICENSE.txt +21 -0
- data/README.md +108 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/firebase-auth-id_token.gemspec +29 -0
- data/lib/firebase/auth/id_token.rb +89 -0
- data/lib/firebase/auth/id_token/config.rb +9 -0
- data/lib/firebase/auth/id_token/errors.rb +20 -0
- data/lib/firebase/auth/id_token/public_keys.rb +51 -0
- data/lib/firebase/auth/id_token/version.rb +7 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 822d4f0601cbbdac7efce34d4b31866a7bf5e569ffbd4b33e845eb7d9b9710ba
|
4
|
+
data.tar.gz: a1536538c494c309af524723085662f27c2adb8731fec045708e929cba6f5dc0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ba1c9d5523b981f0df3f9e22f0cf65907f8201697b628f0e7af3a1035f673c4cdb1e85f9e6d42d5f1ba462ee25637e9afcef1e8a116e0f5d15e44afebc902c10
|
7
|
+
data.tar.gz: ec0e06327ec38afd735e8d6f54589121c7e259f866db1d9617bb31443a9eede0e50b05bc7c89178da5755c24ece9a20f2234940a1df408a71d5dc075a3678639
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
File without changes
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at takehiro0740@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
firebase-auth-id_token (0.1.0)
|
5
|
+
jwt (~> 2.2.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.7.0)
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
12
|
+
coderay (1.1.2)
|
13
|
+
crack (0.4.3)
|
14
|
+
safe_yaml (~> 1.0.0)
|
15
|
+
diff-lcs (1.3)
|
16
|
+
hashdiff (1.0.1)
|
17
|
+
jwt (2.2.1)
|
18
|
+
method_source (1.0.0)
|
19
|
+
pry (0.13.1)
|
20
|
+
coderay (~> 1.1)
|
21
|
+
method_source (~> 1.0)
|
22
|
+
public_suffix (4.0.5)
|
23
|
+
rake (12.3.1)
|
24
|
+
rspec (3.8.0)
|
25
|
+
rspec-core (~> 3.8.0)
|
26
|
+
rspec-expectations (~> 3.8.0)
|
27
|
+
rspec-mocks (~> 3.8.0)
|
28
|
+
rspec-core (3.8.2)
|
29
|
+
rspec-support (~> 3.8.0)
|
30
|
+
rspec-expectations (3.8.4)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.8.0)
|
33
|
+
rspec-mocks (3.8.1)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.8.0)
|
36
|
+
rspec-support (3.8.2)
|
37
|
+
safe_yaml (1.0.5)
|
38
|
+
vcr (5.1.0)
|
39
|
+
webmock (3.8.3)
|
40
|
+
addressable (>= 2.3.6)
|
41
|
+
crack (>= 0.3.2)
|
42
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
43
|
+
webrick (1.6.0)
|
44
|
+
|
45
|
+
PLATFORMS
|
46
|
+
ruby
|
47
|
+
|
48
|
+
DEPENDENCIES
|
49
|
+
firebase-auth-id_token!
|
50
|
+
pry
|
51
|
+
rake (~> 12.0)
|
52
|
+
rspec (~> 3.0)
|
53
|
+
vcr
|
54
|
+
webmock
|
55
|
+
webrick
|
56
|
+
|
57
|
+
BUNDLED WITH
|
58
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Takehiro Adachi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# Firebase Auth ID token verifier
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add the following line to your Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'firebase-auth-id_token'
|
9
|
+
```
|
10
|
+
|
11
|
+
Then run `bundle install`
|
12
|
+
|
13
|
+
Set the following config code as `config/initializers/firebase-auth-id_token.rb`
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
Firebase::Auth::IDToken.configure do |config|
|
17
|
+
config.project_id = 'YOUR_FIREBASE_PROJECT_ID'
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
`YOUR_FIREBASE_PROJECT_ID` could be found at https://console.firebase.google.com
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Use `Firebase::Auth::IDToken#verify!` as below
|
26
|
+
|
27
|
+
### Rails API
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
class ApplicationController < ActionController::API
|
31
|
+
before_action :verify_auth_token!
|
32
|
+
before_action :authenticate_user!
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def authenticate_user!
|
37
|
+
User.find_by!(uid: @auth_token_payload['sub'])
|
38
|
+
rescue ActiveRecord::RecordNotFound
|
39
|
+
head :unauthorized
|
40
|
+
end
|
41
|
+
|
42
|
+
def verify_auth_token!
|
43
|
+
@auth_token_payload = Firebase::Auth::IDToken.new(auth_id_token).verify!
|
44
|
+
# You should refetch ID token on the client side if you receive this 401
|
45
|
+
rescue Firebase::Auth::IDToken::Error::Expired
|
46
|
+
render json: { error: { message: 'Auth ID token expired' } }, status: :unauthorized
|
47
|
+
rescue Firebase::Auth::IDToken::Error::VerificationFail
|
48
|
+
# Notifying to Bugsnag/Sentry here will be nice
|
49
|
+
head :unauthorized
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def auth_id_token
|
55
|
+
request.headers['Authorization']
|
56
|
+
end
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
class UsersController < ApplicationController
|
62
|
+
skip_before_action :authenticate_user!
|
63
|
+
|
64
|
+
def create
|
65
|
+
@user = User.new(user_params)
|
66
|
+
|
67
|
+
if @user.save
|
68
|
+
head :created
|
69
|
+
else
|
70
|
+
render json: { errors: @user.errors.full_messages }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def user_params
|
77
|
+
params.require(:user)
|
78
|
+
.permit(:name)
|
79
|
+
.merge(firebase_auth_uid: @auth_token_payload['sub'])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
```
|
83
|
+
|
84
|
+
## Errors
|
85
|
+
|
86
|
+
### Important ones
|
87
|
+
|
88
|
+
* `Firebase::Auth::IDToken::Error::ProjectIdNotSet` - raised if you haven't set `project_id`
|
89
|
+
* `Firebase::Auth::IDToken::Error::Expired` - raised when the given token is expired, you should return an error code(e.g. 401) to the client so the client can refetch a new token
|
90
|
+
|
91
|
+
### Others
|
92
|
+
|
93
|
+
The following errors will basically be raised when the token is either unable to decode, or invalid.
|
94
|
+
These shouldn't be raised in normal use case, so rescuing the parent class(which is `~::VerificationFail`) and notifying to error monitoring service might be good(see `Usage` section).
|
95
|
+
|
96
|
+
* `Firebase::Auth::IDToken::Error::Expired`
|
97
|
+
* `Firebase::Auth::IDToken::Error::CannotDecode`
|
98
|
+
* `Firebase::Auth::IDToken::Error::IncorrectAlgorithm`
|
99
|
+
* `Firebase::Auth::IDToken::Error::InvalidIat`
|
100
|
+
* `FireBase::Auth::IDToken::Error::InvalidAud`
|
101
|
+
* `FireBase::Auth::IDToken::Error::InvalidIssuer`
|
102
|
+
* `FireBase::Auth::IDToken::Error::InvalidSub`
|
103
|
+
* `FireBase::Auth::IDToken::Error::InvalidAuthTime`
|
104
|
+
|
105
|
+
## FAQs
|
106
|
+
|
107
|
+
* Q. How to retrieve user informations?
|
108
|
+
* A. Best way right now would be by using [googleapis/google-api-ruby-client](https://github.com/googleapis/google-api-ruby-client)'s `Google::Apis::IdentitytoolkitV3::GetAccountInfoRequest`. [Sample code]()
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "firebase/auth/id_token"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'lib/firebase/auth/id_token/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "firebase-auth-id_token"
|
5
|
+
spec.version = Firebase::Auth::IDToken::VERSION
|
6
|
+
spec.authors = ["Takehiro Adachi"]
|
7
|
+
spec.email = ["takehiro0740@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{Small gem which verifies your firebase auth ID token in server side}
|
10
|
+
spec.description = %q{}
|
11
|
+
spec.homepage = "https://github.com/take/firebase-auth-id_token"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
17
|
+
spec.metadata["changelog_uri"] = "https://github.com/take/firebase-auth-id_token/blob/master/CHANGELOG.md"
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_runtime_dependency 'jwt', '~> 2.2.0'
|
29
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'firebase/auth/id_token/version'
|
2
|
+
require 'firebase/auth/id_token/config'
|
3
|
+
require 'firebase/auth/id_token/errors'
|
4
|
+
require 'firebase/auth/id_token/public_keys'
|
5
|
+
require 'jwt'
|
6
|
+
|
7
|
+
module Firebase
|
8
|
+
module Auth
|
9
|
+
class IDToken
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def configure
|
13
|
+
yield config
|
14
|
+
end
|
15
|
+
|
16
|
+
def config
|
17
|
+
@config ||= Config.new
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(token)
|
22
|
+
@token = token
|
23
|
+
raise Error::ProjectIdNotSet.new('project_id is not set, please set') unless self.class.config.project_id
|
24
|
+
end
|
25
|
+
|
26
|
+
def verify!
|
27
|
+
decode!
|
28
|
+
set_certificate
|
29
|
+
verify_decoded_token!
|
30
|
+
verify_token!
|
31
|
+
|
32
|
+
[@payload, @header]
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# https://firebase.google.com/docs/auth/admin/verify-id-tokens#verify_id_tokens_using_a_third-party_jwt_library
|
38
|
+
def decode!
|
39
|
+
@payload, @header = JWT.decode(@token, nil, false)
|
40
|
+
rescue JWT::DecodeError => e
|
41
|
+
raise Error::CannotDecode.new(e.message)
|
42
|
+
end
|
43
|
+
|
44
|
+
def set_certificate
|
45
|
+
@certificate ||= public_keys.find_by!(kid: @header['kid']).certificate
|
46
|
+
end
|
47
|
+
|
48
|
+
def verify_decoded_token!
|
49
|
+
raise Error::InvalidSub.new('Subject Claim should not be empty') if !@payload['sub'] || @payload['sub'] == ''
|
50
|
+
raise Error::InvalidAuthTime.new('Auth Time is lacking') unless @payload['auth_time']
|
51
|
+
raise Error::InvalidAuthTime.new('Auth Time is in future') if Time.now <= Time.at(@payload['auth_time'])
|
52
|
+
end
|
53
|
+
|
54
|
+
def verify_token!
|
55
|
+
JWT.decode(@token, @certificate.public_key, true,
|
56
|
+
{
|
57
|
+
verify_aud: true,
|
58
|
+
aud: self.class.config.project_id,
|
59
|
+
verify_iss: true,
|
60
|
+
iss: iss,
|
61
|
+
verify_iat: true,
|
62
|
+
verify_sub: true,
|
63
|
+
algorithms: ['RS256'],
|
64
|
+
}
|
65
|
+
)
|
66
|
+
rescue JWT::ExpiredSignature => e
|
67
|
+
raise Error::Expired.new(e.message)
|
68
|
+
rescue JWT::IncorrectAlgorithm => e
|
69
|
+
raise Error::IncorrectAlgorithm.new(e.message)
|
70
|
+
rescue JWT::InvalidIatError => e
|
71
|
+
raise Error::InvalidIat.new(e.message)
|
72
|
+
rescue JWT::InvalidAudError => e
|
73
|
+
raise Error::InvalidAud.new(e.message)
|
74
|
+
rescue JWT::InvalidIssuerError => e
|
75
|
+
raise Error::InvalidIssuer.new(e.message)
|
76
|
+
rescue JWT::DecodeError => e
|
77
|
+
raise Error::CannotDecode.new(e.message)
|
78
|
+
end
|
79
|
+
|
80
|
+
def iss
|
81
|
+
"https://securetoken.google.com/#{self.class.config.project_id}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def public_keys
|
85
|
+
@public_keys ||= PublicKeys.new
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Firebase
|
2
|
+
module Auth
|
3
|
+
class IDToken
|
4
|
+
class Error
|
5
|
+
class ProjectIdNotSet < StandardError ; end
|
6
|
+
|
7
|
+
class VerificationFail < StandardError ; end
|
8
|
+
|
9
|
+
class Expired < VerificationFail ; end
|
10
|
+
class CannotDecode < VerificationFail ; end
|
11
|
+
class IncorrectAlgorithm < VerificationFail ; end
|
12
|
+
class InvalidIat < VerificationFail ; end
|
13
|
+
class InvalidAud < VerificationFail ; end
|
14
|
+
class InvalidIssuer < VerificationFail ; end
|
15
|
+
class InvalidSub < VerificationFail ; end
|
16
|
+
class InvalidAuthTime < VerificationFail ; end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
module Firebase
|
5
|
+
module Auth
|
6
|
+
class IDToken
|
7
|
+
class PublicKeys < Array
|
8
|
+
PUBLIC_KEYS_URI = 'https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com'
|
9
|
+
private_constant :PUBLIC_KEYS_URI
|
10
|
+
|
11
|
+
class NotFound < StandardError ; end
|
12
|
+
class FailedToFetchFromRemote < StandardError ; end
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
public_keys_from_remote.each do |kid, certificate|
|
16
|
+
self << PublicKey.new(kid: kid, certificate: certificate)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def find_by!(kid:)
|
21
|
+
public_key = self.find { |public_key| public_key.kid == kid }
|
22
|
+
|
23
|
+
raise NotFound unless public_key
|
24
|
+
|
25
|
+
public_key
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def public_keys_from_remote
|
31
|
+
begin
|
32
|
+
JSON.parse(URI.open(PUBLIC_KEYS_URI).read)
|
33
|
+
rescue OpenURI::HTTPError => e
|
34
|
+
raise FailedToFetchFromRemote.new(e.io.status[1])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
class PublicKey
|
42
|
+
attr_reader :kid, :certificate
|
43
|
+
|
44
|
+
def initialize(kid:, certificate:)
|
45
|
+
@kid = kid
|
46
|
+
@certificate = OpenSSL::X509::Certificate.new(certificate)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: firebase-auth-id_token
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takehiro Adachi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jwt
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.2.0
|
27
|
+
description: ''
|
28
|
+
email:
|
29
|
+
- takehiro0740@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- ".travis.yml"
|
37
|
+
- CHANGELOG.md
|
38
|
+
- CODE_OF_CONDUCT.md
|
39
|
+
- Gemfile
|
40
|
+
- Gemfile.lock
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- bin/console
|
45
|
+
- bin/setup
|
46
|
+
- firebase-auth-id_token.gemspec
|
47
|
+
- lib/firebase/auth/id_token.rb
|
48
|
+
- lib/firebase/auth/id_token/config.rb
|
49
|
+
- lib/firebase/auth/id_token/errors.rb
|
50
|
+
- lib/firebase/auth/id_token/public_keys.rb
|
51
|
+
- lib/firebase/auth/id_token/version.rb
|
52
|
+
homepage: https://github.com/take/firebase-auth-id_token
|
53
|
+
licenses:
|
54
|
+
- MIT
|
55
|
+
metadata:
|
56
|
+
homepage_uri: https://github.com/take/firebase-auth-id_token
|
57
|
+
source_code_uri: https://github.com/take/firebase-auth-id_token
|
58
|
+
changelog_uri: https://github.com/take/firebase-auth-id_token/blob/master/CHANGELOG.md
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 2.3.0
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubygems_version: 3.1.2
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: Small gem which verifies your firebase auth ID token in server side
|
78
|
+
test_files: []
|