Module: ContactAuthHelper
- Included in:
- Cxf::BaseApiController, Cxf::BaseController
- Defined in:
- lib/cxf/helpers/contact_auth_helper.rb
Instance Method Summary collapse
-
#cxf_contact_login(email, password) ⇒ Object
Cxf Contact Login.
-
#cxf_contact_logout ⇒ Object
Cxf Contact Logout.
-
#cxf_contact_magic_link_login(hash, redirect_in_error = false) ⇒ Object
Cxf contact Login.
- #cxf_contact_signed_in? ⇒ Boolean
- #sync_contact_cookies ⇒ Object
Instance Method Details
#cxf_contact_login(email, password) ⇒ Object
Cxf Contact Login.
Starts a contact session in cxf.cloud and set a session cookie
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/cxf/helpers/contact_auth_helper.rb', line 7 def cxf_contact_login(email, password) # Login in cxf response = @cxf_contact.login(email, password) # Get session token from response return response unless response.is_a? Hash if response.key? 'data' id_token = response['data']['contact_token'] || response['data']['id_token'] || nil end @contact_token = id_token response end |
#cxf_contact_logout ⇒ Object
Cxf Contact Logout.
Destroy session from cxf.cloud and delete local session cookie
39 40 41 42 43 44 45 46 47 |
# File 'lib/cxf/helpers/contact_auth_helper.rb', line 39 def cxf_contact_logout # Logout from cxf @cxf_contact.logout # Delete session token and keep the contact token id # Never delete the cxf_contact_id cookie to avoid the creation of ghosts .delete("cxf_contact_access_token") .delete("cxf_contact_refresh_token") @contact_token = nil end |
#cxf_contact_magic_link_login(hash, redirect_in_error = false) ⇒ Object
Cxf contact Login.
Starts a contact session in cxf.cloud and set a session cookie
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/cxf/helpers/contact_auth_helper.rb', line 25 def cxf_contact_magic_link_login(hash, redirect_in_error = false) # Login in cxf response = @cxf_contact.magic_link_login(hash) if response['data'] redirect_to response['data']['redirect_url'] || '/' if redirect_in_error else redirect_to '/' if redirect_in_error end end |
#cxf_contact_signed_in? ⇒ Boolean
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/cxf/helpers/contact_auth_helper.rb', line 49 def cxf_contact_signed_in? begin # Check status in cxf # Check status in cxf response = @cxf_contact.status status = response['success'] || false rescue => e # Handle the client Unauthorized error # if cxf response is negative delete the session cookie .delete("cxf_contact_session_token") .delete("cxf_contact_refresh_token") status = false end status end |
#sync_contact_cookies ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/cxf/helpers/contact_auth_helper.rb', line 67 def = @cxf_contact.get_client. .each do |key, | [['name']] = { value: ['value'], expires: ['expires'] ? Time.parse(['expires']) : nil, path: ['path'] || '/', secure: ['secure'] || false, httponly: ['httponly'] || false, same_site: (['samesite'] || 'Lax').downcase.to_sym } end end |