Class: Ruze::Gigya
- Inherits:
-
Object
- Object
- Ruze::Gigya
- Defined in:
- lib/ruze/gigya.rb
Constant Summary collapse
- BASE_URL =
'https://accounts.eu1.gigya.com'.freeze
- SOCIALIZE_URL =
'https://socialize.eu1.gigya.com'.freeze
Instance Attribute Summary collapse
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
Instance Method Summary collapse
-
#initialize(email, password, device: Device.new) ⇒ Gigya
constructor
A new instance of Gigya.
- #jwt ⇒ Object
- #person_id ⇒ Object
-
#request_verification_code ⇒ Object
Triggers the email verification code and returns the obfuscated address it was sent to.
-
#session_cookie_value ⇒ Object
Logs in using the trusted device and returns the session cookie value.
-
#verify_code(code) ⇒ Object
Completes the 2FA flow with the emailed code, finalizes the device as trusted (remembered for ~30 days) and persists it.
Constructor Details
#initialize(email, password, device: Device.new) ⇒ Gigya
Returns a new instance of Gigya.
11 12 13 14 15 16 17 |
# File 'lib/ruze/gigya.rb', line 11 def initialize(email, password, device: Device.new) raise ArgumentError unless email.is_a?(String) && password.is_a?(String) @email = email @password = password @device = device end |
Instance Attribute Details
#device ⇒ Object (readonly)
Returns the value of attribute device.
18 19 20 |
# File 'lib/ruze/gigya.rb', line 18 def device @device end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
18 19 20 |
# File 'lib/ruze/gigya.rb', line 18 def email @email end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
18 19 20 |
# File 'lib/ruze/gigya.rb', line 18 def password @password end |
Instance Method Details
#jwt ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/ruze/gigya.rb', line 27 def jwt @jwt ||= dig_from post( "#{BASE_URL}/accounts.getJWT", { 'apiKey' => api_key, 'login_token' => , 'fields' => 'data.personId,data.gigyaDataCenter', 'expiration' => 900 } ), label: 'jwt', keys: %w[id_token] end |
#person_id ⇒ Object
20 21 22 23 24 25 |
# File 'lib/ruze/gigya.rb', line 20 def person_id @person_id ||= dig_from post( "#{BASE_URL}/accounts.getAccountInfo", { 'apiKey' => api_key, 'login_token' => } ), label: 'person_id', keys: %w[data personId] end |
#request_verification_code ⇒ Object
Triggers the email verification code and returns the obfuscated address it was sent to. Returns nil when no verification is needed – either the account has no 2FA or this device is already trusted.
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ruze/gigya.rb', line 61 def request_verification_code ids = device_ids reg_token = login_reg_token(ids) return nil unless reg_token assertion = init_tfa(reg_token, ids) mail = first_email(assertion, ids) phv_token = send_verification_code(mail['id'], assertion, ids) @bootstrap = { ids: ids, reg_token: reg_token, assertion: assertion, phv_token: phv_token } mail['obfuscated'] end |
#session_cookie_value ⇒ Object
Logs in using the trusted device and returns the session cookie value. Raises TwoFactorRequired when Renault demands a fresh 2FA verification.
39 40 41 |
# File 'lib/ruze/gigya.rb', line 39 def @session_cookie_value ||= login end |
#verify_code(code) ⇒ Object
Completes the 2FA flow with the emailed code, finalizes the device as trusted (remembered for ~30 days) and persists it.
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ruze/gigya.rb', line 76 def verify_code(code) raise Error, 'Call request_verification_code before verify_code' unless @bootstrap ids = @bootstrap[:ids] provider_assertion = complete_verification(code, ids) finalize_tfa(provider_assertion, ids) @session_cookie_value = login(ids) device.save(gmid: ids[:gmid], ucid: ids[:ucid]) @session_cookie_value end |