firebase-auth-rails 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/firebase/auth/authenticable.rb +55 -46
- data/lib/firebase/auth/rails/version.rb +1 -1
- data/lib/firebase/auth/token.rb +1 -1
- metadata +36 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b925fd8bef4c907add32c7a1bbd57cd7d015d4638123a2e213fa2a1baf55e080
|
4
|
+
data.tar.gz: d91cb3d79a9b15c146db17b66eb4a18313c32b0e0be67283ae6a99f912249462
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60e9147f6e766eb6bcc1f5bb99cb85fa2e142cd15942bdb6bf54c3178170b2473c517486dcaf4bf7a8065d1cad9061b32459e022c2d514245ce961210e3764d4
|
7
|
+
data.tar.gz: 4d0f8c2b3ec9bf579ff77fbf607fa511c6a163339027cd63a5c3155daaf15d8ba7ac19b2b430ab31d7fd2047e53bc85114237e9a6bca2d22577df991832833b6
|
@@ -1,57 +1,66 @@
|
|
1
|
-
module Firebase
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module Firebase
|
2
|
+
module Auth
|
3
|
+
module Authenticable
|
4
|
+
def authenticate_for entity_class
|
5
|
+
getter_name = "current_#{entity_class.to_s.parameterize.underscore}"
|
6
|
+
define_current_entity_getter(entity_class, getter_name)
|
7
|
+
public_send(getter_name)
|
8
|
+
end
|
7
9
|
|
8
|
-
|
10
|
+
private
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
def token
|
13
|
+
params[:token] || token_from_request_headers
|
14
|
+
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
def method_missing(method, *args)
|
17
|
+
prefix, entity_name = method.to_s.split('_', 2)
|
18
|
+
case prefix
|
19
|
+
when 'authenticate'
|
20
|
+
unauthorized_entity unless authenticate_entity(entity_name)
|
21
|
+
when 'current'
|
22
|
+
authenticate_entity(entity_name)
|
23
|
+
else
|
24
|
+
super
|
25
|
+
end
|
26
|
+
end
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
def authenticate_entity(entity_name)
|
29
|
+
if token
|
30
|
+
entity_class = entity_name.camelize.constantize
|
31
|
+
send(:authenticate_for, entity_class)
|
32
|
+
end
|
33
|
+
end
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
35
|
+
def unauthorized_entity
|
36
|
+
head(:unauthorized)
|
37
|
+
end
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
def token_from_request_headers
|
40
|
+
unless request.headers['Authorization'].nil?
|
41
|
+
# FIXME: bearer
|
42
|
+
request.headers['Authorization'].split.last
|
43
|
+
end
|
44
|
+
end
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
46
|
+
def define_current_entity_getter entity_class, getter_name
|
47
|
+
unless self.respond_to?(getter_name)
|
48
|
+
memoization_var_name = "@_#{getter_name}"
|
49
|
+
self.class.send(:define_method, getter_name) do
|
50
|
+
unless instance_variable_defined?(memoization_var_name)
|
51
|
+
# FIXME: error handling
|
52
|
+
firebase_auth_token = Firebase::Auth::Token.new(token: token)
|
53
|
+
current =
|
54
|
+
begin
|
55
|
+
firebase_auth_token.entity_for(entity_class)
|
56
|
+
rescue
|
57
|
+
nil
|
58
|
+
end
|
59
|
+
instance_variable_set(memoization_var_name, current)
|
60
|
+
end
|
61
|
+
instance_variable_get(memoization_var_name)
|
62
|
+
end
|
53
63
|
end
|
54
|
-
instance_variable_get(memoization_var_name)
|
55
64
|
end
|
56
65
|
end
|
57
66
|
end
|
data/lib/firebase/auth/token.rb
CHANGED
@@ -9,7 +9,7 @@ module Firebase
|
|
9
9
|
@token = token
|
10
10
|
@payload = FirebaseIdToken::Signature.verify(token)
|
11
11
|
# user not found or decode error
|
12
|
-
raise StandardError, 'decode error' if @payload.nil?
|
12
|
+
# raise StandardError, 'decode error' if @payload.nil?
|
13
13
|
end
|
14
14
|
|
15
15
|
def entity_for(entity_class)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: firebase-auth-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- penguinwokrs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-retry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rails
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +108,26 @@ dependencies:
|
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: 2.3.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: jwt
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 2.1.0
|
118
|
+
- - "~>"
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '2.1'
|
121
|
+
type: :runtime
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: 2.1.0
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '2.1'
|
97
131
|
description: Description of Firebase::Auth::Rails.
|
98
132
|
email:
|
99
133
|
- dev.and.penguin@gmail.com
|