Module: Sinatra::Jwt::Helpers
- Defined in:
- lib/sinatra/jwt/helpers.rb
Instance Method Summary collapse
- #authorization_token ⇒ Object
- #authorization_token_string ⇒ Object
- #authorize ⇒ Object
- #authorize! ⇒ Object
- #jwt ⇒ Object
- #jwt_decode_options ⇒ Object
- #jwt_header ⇒ Object
- #jwt_payload ⇒ Object
Instance Method Details
#authorization_token ⇒ Object
10 11 12 13 14 |
# File 'lib/sinatra/jwt/helpers.rb', line 10 def @authorization_token ||= .split("Bearer ").last rescue StandardError raise JwtMissingError, "Missing JWT" end |
#authorization_token_string ⇒ Object
6 7 8 |
# File 'lib/sinatra/jwt/helpers.rb', line 6 def @authorization_token_string ||= request.env["HTTP_AUTHORIZATION"] end |
#authorize ⇒ Object
49 50 51 52 53 54 |
# File 'lib/sinatra/jwt/helpers.rb', line 49 def jwt rescue StandardError => e logger&.info({ status: "Unauthorized", message: e. }.to_json) false end |
#authorize! ⇒ Object
43 44 45 46 47 |
# File 'lib/sinatra/jwt/helpers.rb', line 43 def jwt rescue StandardError => e halt 401, { status: "Unauthorized", message: e. }.to_json end |
#jwt ⇒ Object
29 30 31 32 33 |
# File 'lib/sinatra/jwt/helpers.rb', line 29 def jwt @jwt ||= settings.jwt_auth_decoder.decode( , settings.jwt_auth_key, true, ) end |
#jwt_decode_options ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/sinatra/jwt/helpers.rb', line 16 def if settings.jwt_auth_key.nil? { algorithms: settings.jwt_auth_allowed_algorithms, jwks: settings.jwt_auth_jwk_loader } else { algorithm: settings.jwt_auth_algorithm } end end |
#jwt_header ⇒ Object
39 40 41 |
# File 'lib/sinatra/jwt/helpers.rb', line 39 def jwt_header jwt.last end |
#jwt_payload ⇒ Object
35 36 37 |
# File 'lib/sinatra/jwt/helpers.rb', line 35 def jwt_payload jwt.first end |