Class: Aid::Auth::Strategies::TokenOauthV1
- Inherits:
-
BaseStrategy
- Object
- BaseStrategy
- Aid::Auth::Strategies::TokenOauthV1
- Defined in:
- lib/aid/auth/strategies/token_oauth_v1.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#context ⇒ Object
Returns the value of attribute context.
Class Method Summary collapse
Instance Method Summary collapse
- #authenticated? ⇒ Boolean
- #current_user_id ⇒ Object
-
#initialize(config = TokenAuthV1Config.new, context) ⇒ TokenOauthV1
constructor
A new instance of TokenOauthV1.
Constructor Details
#initialize(config = TokenAuthV1Config.new, context) ⇒ TokenOauthV1
Returns a new instance of TokenOauthV1.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/aid/auth/strategies/token_oauth_v1.rb', line 40 def initialize(config=TokenAuthV1Config.new, context) if config.is_a?(Hash) @config = TokenAuthV1Config.new(**config) elsif config.is_a?(TokenAuthV1Config) @config = config end @context = context header = @context.env['HTTP_AUTHORIZATION'] raise ::Aid::Auth::Errors::Unauthorized unless header @token = header.split(' ').last raise ::Aid::Auth::InvalidToken unless @token end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
33 34 35 |
# File 'lib/aid/auth/strategies/token_oauth_v1.rb', line 33 def config @config end |
#context ⇒ Object
Returns the value of attribute context.
33 34 35 |
# File 'lib/aid/auth/strategies/token_oauth_v1.rb', line 33 def context @context end |
Class Method Details
.should_use?(ctx, config) ⇒ Boolean
35 36 37 38 |
# File 'lib/aid/auth/strategies/token_oauth_v1.rb', line 35 def self.should_use?(ctx, config) conf = config.is_a?(TokenAuthV1Config) ? config : TokenAuthV1Config.new(**config) conf.sso_host.present? || ctx.env['HTTP_AUTHORIZATION'].present? end |
Instance Method Details
#authenticated? ⇒ Boolean
57 58 59 |
# File 'lib/aid/auth/strategies/token_oauth_v1.rb', line 57 def authenticated? !!current_user_id end |
#current_user_id ⇒ Object
53 54 55 |
# File 'lib/aid/auth/strategies/token_oauth_v1.rb', line 53 def current_user_id @user_id ||= decode_jwt_token(@token)[0].dig('sub') end |