rack-firebase 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rack/firebase/configuration.rb +2 -1
- data/lib/rack/firebase/middleware.rb +29 -22
- data/lib/rack/firebase/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e56bf82dd7ed836213b95db8e833c94c06c020ba654d4d132c7659dbc30ffbc
|
4
|
+
data.tar.gz: 888ed5477400ef8ba5f5deb9650076b5d2d88554fc750c7e888a8a7780f56267
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be204dc9f7da121a6c72d3f34ad8d74f767e55ac25d357cd9b96588a980501620af57b4678d952f5803f2487f1d456f2d3b06995b94451f4e1f37d21ae078277
|
7
|
+
data.tar.gz: 87b20058c4410c576c0fadc2127c91c9860d16419a8b5bd3cae854e41ff1c613d728d66fb1341d5561ac32b5d8d29ff6c72528340fa812f0c976d2156f5d3c47
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Rack
|
2
2
|
module Firebase
|
3
3
|
class Configuration
|
4
|
-
attr_accessor :project_ids
|
4
|
+
attr_accessor :project_ids, :public_routes
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
reset!
|
@@ -9,6 +9,7 @@ module Rack
|
|
9
9
|
|
10
10
|
def reset!
|
11
11
|
@project_ids = []
|
12
|
+
@public_routes = []
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
@@ -16,30 +16,37 @@ module Rack
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def call(env)
|
19
|
-
|
20
|
-
|
19
|
+
path = env.fetch("PATH_INFO", "no-match")
|
20
|
+
if config.public_routes.none? { |r| r.match(path) }
|
21
|
+
begin
|
22
|
+
token = AuthorizationHeader.read_token(env)
|
23
|
+
decoded_token = TokenDecoder.new.call(token)
|
21
24
|
|
22
|
-
|
23
|
-
|
25
|
+
raise Rack::Firebase::InvalidSubError.new("Invalid subject") if decoded_token["sub"].nil? || decoded_token["sub"] == ""
|
26
|
+
raise Rack::Firebase::InvalidAuthTimeError.new("Invalid auth time") unless decoded_token["auth_time"] <= Time.now.to_i
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
28
|
+
env[USER_UID] = decoded_token["sub"]
|
29
|
+
@app.call(env)
|
30
|
+
rescue JWT::JWKError => error # Issues with fetched JWKs
|
31
|
+
error_responder.call(error, "unauthorized")
|
32
|
+
rescue JWT::ExpiredSignature => error # Token has expired
|
33
|
+
error_responder.call(error, "expired")
|
34
|
+
rescue JWT::InvalidIatError => error # invalid issued at claim (iat)
|
35
|
+
error_responder.call(error, "unauthorized")
|
36
|
+
rescue JWT::InvalidIssuerError => error # invalid issuer
|
37
|
+
error_responder.call(error, "unauthorized")
|
38
|
+
rescue JWT::InvalidAudError => error # invalid audience
|
39
|
+
error_responder.call(error, "unauthorized")
|
40
|
+
rescue JWT::DecodeError => error # General JWT error
|
41
|
+
error_responder.call(error, "unauthorized")
|
42
|
+
rescue Rack::Firebase::InvalidSubError => error # subject is empty or missing
|
43
|
+
error_responder.call(error, "unauthorized")
|
44
|
+
rescue Rack::Firebase::InvalidAuthTimeError => error # auth time is in the future
|
45
|
+
error_responder.call(error, "unauthorized")
|
46
|
+
end
|
47
|
+
else
|
48
|
+
@app.call(env)
|
49
|
+
end
|
43
50
|
end
|
44
51
|
|
45
52
|
private
|