Class: Mumukit::Auth::Token
- Inherits:
-
Object
- Object
- Mumukit::Auth::Token
- Defined in:
- lib/mumukit/auth/token.rb
Instance Attribute Summary collapse
-
#jwt ⇒ Object
readonly
Returns the value of attribute jwt.
Class Method Summary collapse
- .decode(encoded) ⇒ Object
- .decode_header(header) ⇒ Object
- .decoded_secret ⇒ Object
- .encode_dummy_auth_header(metadata) ⇒ Object
- .from_env(env) ⇒ Object
Instance Method Summary collapse
-
#initialize(jwt) ⇒ Token
constructor
A new instance of Token.
- #metadata ⇒ Object
- #permissions(app) ⇒ Object
- #verify_client! ⇒ Object
Constructor Details
#initialize(jwt) ⇒ Token
Returns a new instance of Token.
7 8 9 |
# File 'lib/mumukit/auth/token.rb', line 7 def initialize(jwt) @jwt = jwt end |
Instance Attribute Details
#jwt ⇒ Object (readonly)
Returns the value of attribute jwt.
5 6 7 |
# File 'lib/mumukit/auth/token.rb', line 5 def jwt @jwt end |
Class Method Details
.decode(encoded) ⇒ Object
32 33 34 35 36 |
# File 'lib/mumukit/auth/token.rb', line 32 def self.decode(encoded) Token.new JWT.decode(encoded, decoded_secret)[0] rescue JWT::DecodeError => e raise Mumukit::Auth::InvalidTokenError.new(e) end |
.decode_header(header) ⇒ Object
27 28 29 30 |
# File 'lib/mumukit/auth/token.rb', line 27 def self.decode_header(header) raise Mumukit::Auth::InvalidTokenError.new('missing authorization header') if header.nil? decode header.split(' ').last end |
.decoded_secret ⇒ Object
46 47 48 |
# File 'lib/mumukit/auth/token.rb', line 46 def self.decoded_secret JWT.base64url_decode(Mumukit::Auth.config.client_secret) end |
.encode_dummy_auth_header(metadata) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/mumukit/auth/token.rb', line 38 def self.encode_dummy_auth_header() encoded_token = JWT.encode( {aud: Mumukit::Auth.config.client_id, app_metadata: }, decoded_secret) 'dummy token ' + encoded_token end |
.from_env(env) ⇒ Object
23 24 25 |
# File 'lib/mumukit/auth/token.rb', line 23 def self.from_env(env) new(env.dig('omniauth.auth', 'extra', 'raw_info') || {}) end |
Instance Method Details
#metadata ⇒ Object
11 12 13 |
# File 'lib/mumukit/auth/token.rb', line 11 def ||= Mumukit::Auth::Metadata.new(jwt['app_metadata'] || {}) end |
#permissions(app) ⇒ Object
15 16 17 |
# File 'lib/mumukit/auth/token.rb', line 15 def (app) .(app) end |
#verify_client! ⇒ Object
19 20 21 |
# File 'lib/mumukit/auth/token.rb', line 19 def verify_client! raise Mumukit::Auth::InvalidTokenError.new('aud mismatch') if Mumukit::Auth.config.client_id != jwt['aud'] end |