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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a4081b1727087c19ec8761fafd9d0507f4b398327b3a5458e663569d3381ed8
4
- data.tar.gz: 4196e0601c2552042edac107ff91d1a08cb7df6b66d00b83022184d88da0526e
3
+ metadata.gz: 8e56bf82dd7ed836213b95db8e833c94c06c020ba654d4d132c7659dbc30ffbc
4
+ data.tar.gz: 888ed5477400ef8ba5f5deb9650076b5d2d88554fc750c7e888a8a7780f56267
5
5
  SHA512:
6
- metadata.gz: 41523e3d39d08a86d760b36159a70f4e27ef4c14eb015e2c294e7634995bf6cbbd13a139ef11bdf1b976f305cc12d8cdaefa7990ea9adfe1740766fe73553668
7
- data.tar.gz: 275486512df3b419d95a9dca6b9d0d032f77a768a8ff54b5c84e5dc52ebafbcd9df95adbe8dd3e8695b84b9c072618366e85928516169a48bd110644fc193e53
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
- token = AuthorizationHeader.read_token(env)
20
- decoded_token = TokenDecoder.new.call(token)
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
- raise Rack::Firebase::InvalidSubError.new("Invalid subject") if decoded_token["sub"].nil? || decoded_token["sub"] == ""
23
- raise Rack::Firebase::InvalidAuthTimeError.new("Invalid auth time") unless decoded_token["auth_time"] <= Time.now.to_i
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
- env[USER_UID] = decoded_token["sub"]
26
- @app.call(env)
27
- rescue JWT::JWKError => error # Issues with fetched JWKs
28
- error_responder.call(error, "unauthorized")
29
- rescue JWT::ExpiredSignature => error # Token has expired
30
- error_responder.call(error, "expired")
31
- rescue JWT::InvalidIatError => error # invalid issued at claim (iat)
32
- error_responder.call(error, "unauthorized")
33
- rescue JWT::InvalidIssuerError => error # invalid issuer
34
- error_responder.call(error, "unauthorized")
35
- rescue JWT::InvalidAudError => error # invalid audience
36
- error_responder.call(error, "unauthorized")
37
- rescue JWT::DecodeError => error # General JWT error
38
- error_responder.call(error, "unauthorized")
39
- rescue Rack::Firebase::InvalidSubError => error # subject is empty or missing
40
- error_responder.call(error, "unauthorized")
41
- rescue Rack::Firebase::InvalidAuthTimeError => error # auth time is in the future
42
- error_responder.call(error, "unauthorized")
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
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module Firebase
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-firebase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laura Mosher