Class: Rack::PrxAuth
- Inherits:
-
Object
- Object
- Rack::PrxAuth
- Defined in:
- lib/rack/prx_auth.rb,
lib/rack/prx_auth/version.rb,
lib/rack/prx_auth/token_data.rb,
lib/rack/prx_auth/certificate.rb
Defined Under Namespace
Classes: Certificate, TokenData
Constant Summary collapse
- INVALID_TOKEN =
[ 401, {'Content-Type' => 'application/json'}, [{status: 401, error: 'Invalid JSON Web Token'}.to_json] ]
- DEFAULT_ISS =
'id.prx.org'
- VERSION =
"0.3.0"
Instance Attribute Summary collapse
-
#issuer ⇒ Object
readonly
Returns the value of attribute issuer.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ PrxAuth
constructor
A new instance of PrxAuth.
Constructor Details
#initialize(app, options = {}) ⇒ PrxAuth
Returns a new instance of PrxAuth.
17 18 19 20 21 |
# File 'lib/rack/prx_auth.rb', line 17 def initialize(app, = {}) @app = app @certificate = Certificate.new([:cert_location]) @issuer = [:issuer] || DEFAULT_ISS end |
Instance Attribute Details
#issuer ⇒ Object (readonly)
Returns the value of attribute issuer.
15 16 17 |
# File 'lib/rack/prx_auth.rb', line 15 def issuer @issuer end |
Instance Method Details
#call(env) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rack/prx_auth.rb', line 23 def call(env) return @app.call(env) unless env['HTTP_AUTHORIZATION'] token = env['HTTP_AUTHORIZATION'].split[1] claims = decode_token(token) return @app.call(env) unless should_validate_token?(claims) if valid?(claims, token) env['prx.auth'] = TokenData.new(claims) @app.call(env) else INVALID_TOKEN end end |