Class: SignIn::TokenSerializer
- Inherits:
-
Object
- Object
- SignIn::TokenSerializer
- Defined in:
- app/services/sign_in/token_serializer.rb
Instance Attribute Summary collapse
-
#cookies ⇒ Object
readonly
Returns the value of attribute cookies.
-
#session_container ⇒ Object
readonly
Returns the value of attribute session_container.
Instance Method Summary collapse
- #access_token_expiration ⇒ Object private
- #anti_csrf_enabled_client? ⇒ Boolean private
- #anti_csrf_token ⇒ Object private
- #api_authentication_client? ⇒ Boolean private
- #client_config ⇒ Object private
- #cookie_authentication_client? ⇒ Boolean private
- #device_secret ⇒ Object private
- #device_secret_enabled_client? ⇒ Boolean private
- #encoded_access_token ⇒ Object private
- #encrypted_refresh_token ⇒ Object private
- #info_cookie_value ⇒ Object private
-
#initialize(session_container:, cookies:) ⇒ TokenSerializer
constructor
A new instance of TokenSerializer.
- #mock_authentication_client? ⇒ Boolean private
- #perform ⇒ Object
- #session_expiration ⇒ Object private
- #set_cookie!(name:, value:, httponly:, domain: nil, path: '/') ⇒ Object private
- #set_cookies ⇒ Object private
- #token_json_payload ⇒ Object private
- #token_json_response ⇒ Object private
Constructor Details
#initialize(session_container:, cookies:) ⇒ TokenSerializer
Returns a new instance of TokenSerializer.
7 8 9 10 |
# File 'app/services/sign_in/token_serializer.rb', line 7 def initialize(session_container:, cookies:) @session_container = session_container @cookies = end |
Instance Attribute Details
#cookies ⇒ Object (readonly)
Returns the value of attribute cookies.
5 6 7 |
# File 'app/services/sign_in/token_serializer.rb', line 5 def @cookies end |
#session_container ⇒ Object (readonly)
Returns the value of attribute session_container.
5 6 7 |
# File 'app/services/sign_in/token_serializer.rb', line 5 def session_container @session_container end |
Instance Method Details
#access_token_expiration ⇒ Object (private)
108 109 110 |
# File 'app/services/sign_in/token_serializer.rb', line 108 def access_token_expiration @access_token_expiration ||= session_container.access_token.expiration_time end |
#anti_csrf_enabled_client? ⇒ Boolean (private)
96 97 98 |
# File 'app/services/sign_in/token_serializer.rb', line 96 def anti_csrf_enabled_client? client_config.anti_csrf end |
#anti_csrf_token ⇒ Object (private)
121 122 123 |
# File 'app/services/sign_in/token_serializer.rb', line 121 def anti_csrf_token @anti_csrf_token ||= session_container.anti_csrf_token end |
#api_authentication_client? ⇒ Boolean (private)
88 89 90 |
# File 'app/services/sign_in/token_serializer.rb', line 88 def api_authentication_client? client_config.api_auth? end |
#client_config ⇒ Object (private)
125 126 127 |
# File 'app/services/sign_in/token_serializer.rb', line 125 def client_config @client_config ||= session_container.client_config end |
#cookie_authentication_client? ⇒ Boolean (private)
84 85 86 |
# File 'app/services/sign_in/token_serializer.rb', line 84 def client_config. end |
#device_secret ⇒ Object (private)
100 101 102 |
# File 'app/services/sign_in/token_serializer.rb', line 100 def device_secret @device_secret ||= session_container.device_secret end |
#device_secret_enabled_client? ⇒ Boolean (private)
80 81 82 |
# File 'app/services/sign_in/token_serializer.rb', line 80 def device_secret_enabled_client? api_authentication_client? && client_config.shared_sessions && device_secret end |
#encoded_access_token ⇒ Object (private)
117 118 119 |
# File 'app/services/sign_in/token_serializer.rb', line 117 def encoded_access_token @encoded_access_token ||= AccessTokenJwtEncoder.new(access_token: session_container.access_token).perform end |
#encrypted_refresh_token ⇒ Object (private)
112 113 114 115 |
# File 'app/services/sign_in/token_serializer.rb', line 112 def encrypted_refresh_token @encrypted_refresh_token ||= RefreshTokenEncryptor.new(refresh_token: session_container.refresh_token).perform end |
#info_cookie_value ⇒ Object (private)
60 61 62 63 64 65 |
# File 'app/services/sign_in/token_serializer.rb', line 60 def { access_token_expiration:, refresh_token_expiration: session_expiration } end |
#mock_authentication_client? ⇒ Boolean (private)
92 93 94 |
# File 'app/services/sign_in/token_serializer.rb', line 92 def mock_authentication_client? client_config.mock_auth? end |
#perform ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/services/sign_in/token_serializer.rb', line 12 def perform if {} elsif api_authentication_client? token_json_response elsif mock_authentication_client? token_json_response end end |
#session_expiration ⇒ Object (private)
104 105 106 |
# File 'app/services/sign_in/token_serializer.rb', line 104 def session_expiration @session_expiration ||= session_container.session.refresh_expiration end |
#set_cookie!(name:, value:, httponly:, domain: nil, path: '/') ⇒ Object (private)
49 50 51 52 53 54 55 56 57 58 |
# File 'app/services/sign_in/token_serializer.rb', line 49 def (name:, value:, httponly:, domain: nil, path: '/') [name] = { value:, expires: session_expiration, secure: Settings.sign_in., httponly:, path:, domain: }.compact end |
#set_cookies ⇒ Object (private)
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/services/sign_in/token_serializer.rb', line 26 def (name: Constants::Auth::ACCESS_TOKEN_COOKIE_NAME, value: encoded_access_token, httponly: true, domain: :all) (name: Constants::Auth::REFRESH_TOKEN_COOKIE_NAME, value: encrypted_refresh_token, httponly: true, path: Constants::Auth::REFRESH_ROUTE_PATH) (name: Constants::Auth::INFO_COOKIE_NAME, value: .to_json, httponly: false, domain: Settings.sign_in.) if anti_csrf_enabled_client? (name: Constants::Auth::ANTI_CSRF_COOKIE_NAME, value: anti_csrf_token, httponly: true) end end |
#token_json_payload ⇒ Object (private)
71 72 73 74 75 76 77 78 |
# File 'app/services/sign_in/token_serializer.rb', line 71 def token_json_payload payload = {} payload[:refresh_token] = encrypted_refresh_token payload[:access_token] = encoded_access_token payload[:anti_csrf_token] = anti_csrf_token if anti_csrf_enabled_client? payload[:device_secret] = device_secret if device_secret_enabled_client? payload end |
#token_json_response ⇒ Object (private)
67 68 69 |
# File 'app/services/sign_in/token_serializer.rb', line 67 def token_json_response { data: token_json_payload } end |