firebase-auth-id_token_keeper 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +83 -2
- data/lib/firebase/auth/id_token_keeper/id_token.rb +2 -0
- data/lib/firebase/auth/id_token_keeper/testing.rb +29 -0
- data/lib/firebase/auth/id_token_keeper/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b54959ace13bc7c20d267f3479311115a1c8b79c1d98d07de5486da0f3e1329
|
4
|
+
data.tar.gz: a6d1ee1877bb6db27f8093efa0a94f1dfccf90954a071ea3cbf58a625e241128
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5c1024769e1fae108c4c0f0610342b867ae9a8c8e878a469ed18a6e91e3c3843fa2f4033c2406c58980ef8bf527bd3ade3287ac14a1462c0ade5e25cf5b1c46
|
7
|
+
data.tar.gz: 5e04d018ea3fe0fbd120b45df7de1abac4f068dca8b5bea0125d14ead395e9b8650861edcb2ecc06c926a36a0620240aba1fdc151d2ef1f23e138cdb9bac8be4
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/README.md
CHANGED
@@ -1,8 +1,89 @@
|
|
1
1
|
# Firebase::Auth::IDTokenKeeper
|
2
2
|
|
3
|
-
|
3
|
+
## Errors
|
4
4
|
|
5
|
-
|
5
|
+
### Response body
|
6
|
+
|
7
|
+
```json
|
8
|
+
{
|
9
|
+
"error": "<message>"
|
10
|
+
}
|
11
|
+
```
|
12
|
+
|
13
|
+
### Type
|
14
|
+
|
15
|
+
- `JWT::ExpiredSignature`
|
16
|
+
- code: 401
|
17
|
+
- message: "Signature has expired."
|
18
|
+
- You should refresh your token on the client side.
|
19
|
+
- `JWT::DecodeError`
|
20
|
+
- code: 401
|
21
|
+
- message: "Invalid JWT format."
|
22
|
+
- You should send JWT with valid format.
|
23
|
+
|
24
|
+
|
25
|
+
## Test
|
26
|
+
|
27
|
+
We provide test id token generate method.
|
28
|
+
|
29
|
+
It can use like this.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
decoded_jwt = {
|
33
|
+
"iss"=>"https://example.com/project-id",
|
34
|
+
"name"=>"Test Example",
|
35
|
+
"picture"=>"https://example.com",
|
36
|
+
"aud"=>"project-id",
|
37
|
+
"auth_time"=>1535353624,
|
38
|
+
"user_id"=>"badcd9971aa1ba6a46bf3379db78",
|
39
|
+
"sub"=>"teyOh0wMQyZQboYCW18wammaFkH2",
|
40
|
+
"iat"=>1535353624,
|
41
|
+
"exp"=>1535357224,
|
42
|
+
"email"=>"test.example@example.com",
|
43
|
+
"email_verified"=>false,
|
44
|
+
"firebase"=>{"identities"=>{"github.com"=>["xxxxxx"], "email"=>["test.example@example.com"]}, "sign_in_provider"=>"github.com"}
|
45
|
+
}
|
46
|
+
|
47
|
+
encoded_jwt = Firebase::Auth::IDTokenKeeper::Testing.generate_test_id_token(decoded_jwt)
|
48
|
+
# => "eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJpc3MiOiJodHRwczovL2V4YW1wbGUuY29tL3Byb2plY3QtaWQiLCJuYW1lIjoiVGVzdCBFeGFtcGxlIiwicGljdHVyZSI6Imh0dHBzOi8vZXhhbXBsZS5jb20iLCJhdWQiOiJwcm9qZWN0LWlkIiwiYXV0aF90aW1lIjoxNTM1MzUzNjI0LCJ1c2VyX2lkIjoiYmFkY2Q5OTcxYWExYmE2YTQ2YmYzMzc5ZGI3OCIsInN1YiI6InRleU9oMHdNUXlaUWJvWUNXMTh3YW1tYUZrSDIiLCJpYXQiOjE1MzUzNTM2MjQsImV4cCI6MTUzNTM1NzIyNCwiZW1haWwiOiJ0ZXN0LmV4YW1wbGVAZXhhbXBsZS5jb20iLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsImZpcmViYXNlIjp7ImlkZW50aXRpZXMiOnsiZ2l0aHViLmNvbSI6WyJ4eHh4eHgiXSwiZW1haWwiOlsidGVzdC5leGFtcGxlQGV4YW1wbGUuY29tIl19LCJzaWduX2luX3Byb3ZpZGVyIjoiZ2l0aHViLmNvbSJ9fQ."
|
49
|
+
|
50
|
+
Firebase::Auth::IDTokenKeeper::Testing.decode_test_id_token(encoded_jwt)
|
51
|
+
# => {
|
52
|
+
# "iss"=>"https://example.com/project-id",
|
53
|
+
# "name"=>"Test Example",
|
54
|
+
# "picture"=>"https://example.com",
|
55
|
+
# "aud"=>"project-id",
|
56
|
+
# "auth_time"=>1535353624,
|
57
|
+
# "user_id"=>"badcd9971aa1ba6a46bf3379db78",
|
58
|
+
# "sub"=>"teyOh0wMQyZQboYCW18wammaFkH2",
|
59
|
+
# "iat"=>1535353624,
|
60
|
+
# "exp"=>1535357224,
|
61
|
+
# "email"=>"test.example@example.com",
|
62
|
+
# "email_verified"=>false,
|
63
|
+
# "firebase"=>{"identities"=>{"github.com"=>["xxxxxx"], "email"=>["test.example@example.com"]}, "sign_in_provider"=>"github.com"}
|
64
|
+
# }
|
65
|
+
```
|
66
|
+
|
67
|
+
### For RSpec
|
68
|
+
|
69
|
+
Make a support file `spec/support/firebase_auth_id_token_keeper.rb` which contains following code.
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
RSpec.configure do |config|
|
73
|
+
config.include Firebase::Auth::IDTokenKeeper::Test::Helpers, type: :request
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
Load the support file in your `spec/rails_helper.rb`.
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
...
|
81
|
+
# Add additional requires below this line. Rails is not loaded until this point!
|
82
|
+
require 'support/firebase_auth_id_token_keeper'
|
83
|
+
...
|
84
|
+
```
|
85
|
+
|
86
|
+
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.
|
6
87
|
|
7
88
|
## Installation
|
8
89
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Firebase
|
4
|
+
module Auth
|
5
|
+
module IDTokenKeeper
|
6
|
+
module Testing
|
7
|
+
|
8
|
+
def self.generate_test_id_token(decoded_jwt)
|
9
|
+
JWT.encode(decoded_jwt, nil, 'none')
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.decode_test_id_token(encoded_jwt)
|
13
|
+
JWT.decode(encoded_jwt, nil, false)
|
14
|
+
end
|
15
|
+
|
16
|
+
module Helpers
|
17
|
+
extend ActiveSupport::Concern
|
18
|
+
|
19
|
+
::Firebase::Auth::IDTokenKeeper::IDToken.class_eval do
|
20
|
+
def verified_id_token
|
21
|
+
::Firebase::Auth::IDTokenKeeper::Testing.decode_test_id_token(encoded_jwt)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: firebase-auth-id_token_keeper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rui Onodera
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jwt
|
@@ -88,6 +88,7 @@ executables: []
|
|
88
88
|
extensions: []
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
|
+
- ".gitignore"
|
91
92
|
- CODE_OF_CONDUCT.md
|
92
93
|
- Gemfile
|
93
94
|
- Gemfile.lock
|
@@ -101,6 +102,7 @@ files:
|
|
101
102
|
- lib/firebase/auth/id_token_keeper/config.rb
|
102
103
|
- lib/firebase/auth/id_token_keeper/id_token.rb
|
103
104
|
- lib/firebase/auth/id_token_keeper/public_keys_endpoint.rb
|
105
|
+
- lib/firebase/auth/id_token_keeper/testing.rb
|
104
106
|
- lib/firebase/auth/id_token_keeper/version.rb
|
105
107
|
- lib/generators/firebase/auth/id_token_keeper/install_generator.rb
|
106
108
|
- lib/generators/firebase/auth/id_token_keeper/templates/firebase_auth_id_token_keeper.rb
|