Class: SignIn::TokenExchanger
- Inherits:
-
Object
- Object
- SignIn::TokenExchanger
- Includes:
- ActiveModel::Validations
- Defined in:
- app/services/sign_in/token_exchanger.rb
Instance Attribute Summary collapse
-
#actor_token ⇒ Object
readonly
Returns the value of attribute actor_token.
-
#actor_token_type ⇒ Object
readonly
Returns the value of attribute actor_token_type.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#subject_token ⇒ Object
readonly
Returns the value of attribute subject_token.
-
#subject_token_type ⇒ Object
readonly
Returns the value of attribute subject_token_type.
Instance Method Summary collapse
- #create_new_session ⇒ Object private
- #current_access_token ⇒ Object private
- #current_client_config ⇒ Object private
- #current_session ⇒ Object private
- #hashed_actor_token ⇒ Object private
-
#initialize(subject_token:, subject_token_type:, actor_token:, actor_token_type:, client_id:) ⇒ TokenExchanger
constructor
A new instance of TokenExchanger.
- #new_session_client_config ⇒ Object private
- #perform ⇒ Object
- #valid_actor_token? ⇒ Boolean private
- #validate_actor_token! ⇒ Object private
- #validate_actor_token_type! ⇒ Object private
- #validate_client_id! ⇒ Object private
- #validate_device_sso! ⇒ Object private
- #validate_shared_sessions_client! ⇒ Object private
- #validate_subject_token! ⇒ Object private
- #validate_subject_token_type! ⇒ Object private
Constructor Details
#initialize(subject_token:, subject_token_type:, actor_token:, actor_token_type:, client_id:) ⇒ TokenExchanger
Returns a new instance of TokenExchanger.
17 18 19 20 21 22 23 |
# File 'app/services/sign_in/token_exchanger.rb', line 17 def initialize(subject_token:, subject_token_type:, actor_token:, actor_token_type:, client_id:) @subject_token = subject_token @subject_token_type = subject_token_type @actor_token = actor_token @actor_token_type = actor_token_type @client_id = client_id end |
Instance Attribute Details
#actor_token ⇒ Object (readonly)
Returns the value of attribute actor_token.
7 8 9 |
# File 'app/services/sign_in/token_exchanger.rb', line 7 def actor_token @actor_token end |
#actor_token_type ⇒ Object (readonly)
Returns the value of attribute actor_token_type.
7 8 9 |
# File 'app/services/sign_in/token_exchanger.rb', line 7 def actor_token_type @actor_token_type end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
7 8 9 |
# File 'app/services/sign_in/token_exchanger.rb', line 7 def client_id @client_id end |
#subject_token ⇒ Object (readonly)
Returns the value of attribute subject_token.
7 8 9 |
# File 'app/services/sign_in/token_exchanger.rb', line 7 def subject_token @subject_token end |
#subject_token_type ⇒ Object (readonly)
Returns the value of attribute subject_token_type.
7 8 9 |
# File 'app/services/sign_in/token_exchanger.rb', line 7 def subject_token_type @subject_token_type end |
Instance Method Details
#create_new_session ⇒ Object (private)
81 82 83 |
# File 'app/services/sign_in/token_exchanger.rb', line 81 def create_new_session SessionSpawner.new(current_session:, new_session_client_config:).perform end |
#current_access_token ⇒ Object (private)
89 90 91 |
# File 'app/services/sign_in/token_exchanger.rb', line 89 def current_access_token @current_access_token ||= AccessTokenJwtDecoder.new(access_token_jwt: subject_token).perform end |
#current_client_config ⇒ Object (private)
97 98 99 |
# File 'app/services/sign_in/token_exchanger.rb', line 97 def current_client_config @current_client_config ||= ClientConfig.find_by(client_id: current_access_token.client_id) end |
#current_session ⇒ Object (private)
93 94 95 |
# File 'app/services/sign_in/token_exchanger.rb', line 93 def current_session @current_session ||= OAuthSession.find_by(handle: current_access_token.session_handle) end |
#hashed_actor_token ⇒ Object (private)
59 60 61 |
# File 'app/services/sign_in/token_exchanger.rb', line 59 def hashed_actor_token @hashed_actor_token ||= Digest::SHA256.hexdigest(actor_token) end |
#new_session_client_config ⇒ Object (private)
85 86 87 |
# File 'app/services/sign_in/token_exchanger.rb', line 85 def new_session_client_config @new_session_client_config ||= ClientConfig.find_by(client_id:) end |
#perform ⇒ Object
25 26 27 28 |
# File 'app/services/sign_in/token_exchanger.rb', line 25 def perform validate! create_new_session end |
#valid_actor_token? ⇒ Boolean (private)
54 55 56 57 |
# File 'app/services/sign_in/token_exchanger.rb', line 54 def valid_actor_token? hashed_actor_token == current_session.hashed_device_secret && hashed_actor_token == current_access_token.device_secret_hash end |
#validate_actor_token! ⇒ Object (private)
50 51 52 |
# File 'app/services/sign_in/token_exchanger.rb', line 50 def validate_actor_token! raise Errors::InvalidTokenError.new message: 'actor token is invalid' unless valid_actor_token? end |
#validate_actor_token_type! ⇒ Object (private)
44 45 46 47 48 |
# File 'app/services/sign_in/token_exchanger.rb', line 44 def validate_actor_token_type! unless actor_token_type == Constants::Urn::DEVICE_SECRET raise Errors::InvalidTokenTypeError.new message: 'actor token type is invalid' end end |
#validate_client_id! ⇒ Object (private)
63 64 65 66 67 |
# File 'app/services/sign_in/token_exchanger.rb', line 63 def validate_client_id! unless new_session_client_config raise Errors::InvalidClientConfigError.new message: 'client configuration not found' end end |
#validate_device_sso! ⇒ Object (private)
75 76 77 78 79 |
# File 'app/services/sign_in/token_exchanger.rb', line 75 def validate_device_sso! unless current_client_config.device_sso_enabled? raise Errors::InvalidSSORequestError.new message: 'token exchange requested from invalid client' end end |
#validate_shared_sessions_client! ⇒ Object (private)
69 70 71 72 73 |
# File 'app/services/sign_in/token_exchanger.rb', line 69 def validate_shared_sessions_client! unless new_session_client_config.shared_sessions raise Errors::InvalidClientConfigError.new message: 'tokens requested for client without shared sessions' end end |
#validate_subject_token! ⇒ Object (private)
32 33 34 35 36 |
# File 'app/services/sign_in/token_exchanger.rb', line 32 def validate_subject_token! unless subject_token && current_access_token raise Errors::InvalidTokenError.new message: 'subject token is invalid' end end |
#validate_subject_token_type! ⇒ Object (private)
38 39 40 41 42 |
# File 'app/services/sign_in/token_exchanger.rb', line 38 def validate_subject_token_type! unless subject_token_type == Constants::Urn::ACCESS_TOKEN raise Errors::InvalidTokenTypeError.new message: 'subject token type is invalid' end end |