firebase_token_auth 1.4.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +7 -4
- data/README.md +20 -0
- data/lib/firebase_token_auth/admin_client.rb +9 -0
- data/lib/firebase_token_auth/client.rb +5 -1
- data/lib/firebase_token_auth/configuration.rb +2 -2
- data/lib/firebase_token_auth/validator.rb +5 -0
- data/lib/firebase_token_auth/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 197296c820b4912863ba1bb7e0d312be53e36baaada6f1b80d265c38191c430d
|
4
|
+
data.tar.gz: b9a6bbbca9480b5e7d57afccb89c8c65044e87ad35a66f746d297a69fc9d97d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1e2537dc84f0d5aef2ceabd2893b7cc0bc09b9b806892955a7608c0525bba8efa99b1058ff7292b43a103122f6f074ea69cbd6f9fadaa0fb1eb2a54d81d728a
|
7
|
+
data.tar.gz: 3cc646d76aa797cb741ad1ad8a5d6b4c67080f2e62b34b9d46c05b47dd4052c91faa1abbf488390725262b57b4ba763ca342314807f4a92d862c03b839e8fb36
|
data/.github/workflows/test.yml
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
name: rspec
|
2
2
|
|
3
|
-
on:
|
3
|
+
on:
|
4
|
+
workflow_dispatch:
|
5
|
+
push:
|
4
6
|
|
5
7
|
jobs:
|
6
8
|
rspec:
|
7
9
|
runs-on: ubuntu-latest
|
8
10
|
strategy:
|
9
11
|
matrix:
|
10
|
-
ruby: [ 2.6, 2.7, "3.0", 3.1, 3.2 ]
|
12
|
+
ruby: [ 2.6, 2.7, "3.0", 3.1, 3.2, 3.3 ]
|
11
13
|
steps:
|
12
14
|
- uses: actions/checkout@v3
|
13
15
|
|
@@ -18,9 +20,10 @@ jobs:
|
|
18
20
|
|
19
21
|
- name: Configure Bundler
|
20
22
|
run: |
|
21
|
-
|
23
|
+
ruby -v
|
24
|
+
# gem update --system
|
22
25
|
gem --version
|
23
|
-
gem install -N bundler -v 2
|
26
|
+
gem install -N bundler -v 2.4
|
24
27
|
|
25
28
|
- uses: actions/cache@v3
|
26
29
|
with:
|
data/README.md
CHANGED
@@ -91,6 +91,26 @@ puts c_token
|
|
91
91
|
# => "eyJhbGciOXXX.eyJpc3MiOiJmaXJlYmFzXXXX.v7y7LoBXXXXX" # dummy
|
92
92
|
```
|
93
93
|
|
94
|
+
### verify custom token
|
95
|
+
```ruby
|
96
|
+
require 'firebase_token_auth'
|
97
|
+
|
98
|
+
FirebaseTokenAuth.configure do |config|
|
99
|
+
config.project_id = 'your_project_id'
|
100
|
+
config.json_key_io = "#{Rails.root}/path/to/service_account_credentials.json"
|
101
|
+
end
|
102
|
+
|
103
|
+
client = FirebaseTokenAuth.build
|
104
|
+
result = client.verify_custom_token(custom_token)
|
105
|
+
|
106
|
+
puts result
|
107
|
+
# => {:expires_in=>3600,
|
108
|
+
# :id_token=>"<id_token>",
|
109
|
+
# :is_new_user=>"<true/false>",
|
110
|
+
# :kind=>"identitytoolkit#VerifyCustomTokenResponse",
|
111
|
+
# :refresh_token=>"<refresh_token>"}
|
112
|
+
```
|
113
|
+
|
94
114
|
### fetch users info from firebase
|
95
115
|
```ruby
|
96
116
|
require 'firebase_token_auth'
|
@@ -20,6 +20,15 @@ module FirebaseTokenAuth
|
|
20
20
|
service.set_account_info(request)
|
21
21
|
end
|
22
22
|
|
23
|
+
def verify_custom_token(custom_token)
|
24
|
+
request = Google::Apis::IdentitytoolkitV3::VerifyCustomTokenRequest.new(
|
25
|
+
token: custom_token,
|
26
|
+
return_secure_token: true
|
27
|
+
)
|
28
|
+
|
29
|
+
service.verify_custom_token(request)
|
30
|
+
end
|
31
|
+
|
23
32
|
private
|
24
33
|
|
25
34
|
def permit_attributes(attr_hash)
|
@@ -47,10 +47,14 @@ module FirebaseTokenAuth
|
|
47
47
|
iat: now_seconds,
|
48
48
|
exp: now_seconds + (60 * 60),
|
49
49
|
uid: uid }
|
50
|
-
payload.merge!({
|
50
|
+
payload.merge!({ claims: additional_claims }) if additional_claims
|
51
51
|
JWT.encode(payload, configuration.private_key, ALGORITHM)
|
52
52
|
end
|
53
53
|
|
54
|
+
def verify_custom_token(custom_token)
|
55
|
+
admin_client.verify_custom_token(custom_token).to_h
|
56
|
+
end
|
57
|
+
|
54
58
|
def user_search_by_email(email)
|
55
59
|
admin_client.get_account_info({ email: [email] })&.users&.map(&:to_h)
|
56
60
|
end
|
@@ -29,7 +29,7 @@ module FirebaseTokenAuth
|
|
29
29
|
|
30
30
|
@auth = if json_key_io
|
31
31
|
io = json_key_io.respond_to?(:read) ? json_key_io : File.open(json_key_io)
|
32
|
-
io.rewind if io.respond_to?(:read)
|
32
|
+
io.rewind if io.respond_to?(:read)
|
33
33
|
Google::Auth::ServiceAccountCredentials.make_creds(
|
34
34
|
json_key_io: io,
|
35
35
|
scope: scope
|
@@ -41,7 +41,7 @@ module FirebaseTokenAuth
|
|
41
41
|
|
42
42
|
if json_key_io
|
43
43
|
json_io = json_key_io.respond_to?(:read) ? json_key_io : File.open(json_key_io)
|
44
|
-
json_io.rewind if json_key_io.respond_to?(:read)
|
44
|
+
json_io.rewind if json_key_io.respond_to?(:read)
|
45
45
|
parsed = JSON.parse(json_io.read)
|
46
46
|
@private_key = OpenSSL::PKey::RSA.new(parsed['private_key'])
|
47
47
|
@client_email = parsed['client_email']
|
@@ -14,11 +14,16 @@ module FirebaseTokenAuth
|
|
14
14
|
raise ValidationError, 'Firebase ID token has no "sub" (subject) claim.' unless payload['sub'].is_a?(String)
|
15
15
|
raise ValidationError, 'Firebase ID token has an empty string "sub" (subject) claim.' if payload['sub'].empty?
|
16
16
|
raise ValidationError, 'Firebase ID token has "sub" (subject) claim longer than 128 characters.' if payload['sub'].size > 128
|
17
|
+
raise ValidationError, 'Firebase ID token has expired.' if expired?(payload['exp'])
|
17
18
|
end
|
18
19
|
|
19
20
|
def extract_kid(id_token)
|
20
21
|
decoded = JWT.decode(id_token, nil, false, algorithm: ALGORITHM)
|
21
22
|
[decoded[1]['kid'], decoded]
|
22
23
|
end
|
24
|
+
|
25
|
+
def expired?(exp)
|
26
|
+
exp.to_i <= Time.now.to_i
|
27
|
+
end
|
23
28
|
end
|
24
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: firebase_token_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- miyataka
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-apis-identitytoolkit_v3
|
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
- !ruby/object:Gem::Version
|
87
87
|
version: '0'
|
88
88
|
requirements: []
|
89
|
-
rubygems_version: 3.
|
89
|
+
rubygems_version: 3.5.3
|
90
90
|
signing_key:
|
91
91
|
specification_version: 4
|
92
92
|
summary: Firebase Authentication API wrapper for serverside. It support custom token
|