Module: Descope::Api::V1::Auth::OTP
- Included in:
- Descope::Api::V1::Auth
- Defined in:
- lib/descope/api/v1/auth/otp.rb
Overview
Holds all the password API calls
Constant Summary
Constants included from Mixins::Common::EndpointsV2
Mixins::Common::EndpointsV2::PUBLIC_KEY_PATH
Constants included from Mixins::Common::EndpointsV1
Mixins::Common::EndpointsV1::AUTH_SAML_START_PATH, Mixins::Common::EndpointsV1::EXCHANGE_AUTH_ACCESS_KEY_PATH, Mixins::Common::EndpointsV1::GET_SESSION_ENCHANTEDLINK_AUTH_PATH, Mixins::Common::EndpointsV1::GET_SESSION_MAGICLINK_AUTH_PATH, Mixins::Common::EndpointsV1::HISTORY_PATH, Mixins::Common::EndpointsV1::LOGOUT_ALL_PATH, Mixins::Common::EndpointsV1::LOGOUT_PATH, Mixins::Common::EndpointsV1::ME_PATH, Mixins::Common::EndpointsV1::OAUTH_CREATE_REDIRECT_URL_FOR_SIGN_IN_REQUEST_PATH, Mixins::Common::EndpointsV1::OAUTH_CREATE_REDIRECT_URL_FOR_SIGN_UP_REQUEST_PATH, Mixins::Common::EndpointsV1::OAUTH_EXCHANGE_TOKEN_PATH, Mixins::Common::EndpointsV1::OAUTH_START_PATH, Mixins::Common::EndpointsV1::PASSWORD_POLICY_PATH, Mixins::Common::EndpointsV1::REFRESH_TOKEN_PATH, Mixins::Common::EndpointsV1::REPLACE_PASSWORD_PATH, Mixins::Common::EndpointsV1::SAML_EXCHANGE_TOKEN_PATH, Mixins::Common::EndpointsV1::SELECT_TENANT_PATH, Mixins::Common::EndpointsV1::SEND_RESET_PASSWORD_PATH, Mixins::Common::EndpointsV1::SIGN_IN_AUTH_ENCHANTEDLINK_PATH, Mixins::Common::EndpointsV1::SIGN_IN_AUTH_MAGICLINK_PATH, Mixins::Common::EndpointsV1::SIGN_IN_AUTH_OTP_PATH, Mixins::Common::EndpointsV1::SIGN_IN_AUTH_WEBAUTHN_FINISH_PATH, Mixins::Common::EndpointsV1::SIGN_IN_AUTH_WEBAUTHN_START_PATH, Mixins::Common::EndpointsV1::SIGN_IN_PASSWORD_PATH, Mixins::Common::EndpointsV1::SIGN_UP_AUTH_ENCHANTEDLINK_PATH, Mixins::Common::EndpointsV1::SIGN_UP_AUTH_MAGICLINK_PATH, Mixins::Common::EndpointsV1::SIGN_UP_AUTH_OTP_PATH, Mixins::Common::EndpointsV1::SIGN_UP_AUTH_TOTP_PATH, Mixins::Common::EndpointsV1::SIGN_UP_AUTH_WEBAUTHN_FINISH_PATH, Mixins::Common::EndpointsV1::SIGN_UP_AUTH_WEBAUTHN_START_PATH, Mixins::Common::EndpointsV1::SIGN_UP_OR_IN_AUTH_ENCHANTEDLINK_PATH, Mixins::Common::EndpointsV1::SIGN_UP_OR_IN_AUTH_MAGICLINK_PATH, Mixins::Common::EndpointsV1::SIGN_UP_OR_IN_AUTH_OTP_PATH, Mixins::Common::EndpointsV1::SIGN_UP_OR_IN_AUTH_WEBAUTHN_START_PATH, Mixins::Common::EndpointsV1::SIGN_UP_PASSWORD_PATH, Mixins::Common::EndpointsV1::UPDATE_AUTH_WEBAUTHN_FINISH_PATH, Mixins::Common::EndpointsV1::UPDATE_AUTH_WEBAUTHN_START_PATH, Mixins::Common::EndpointsV1::UPDATE_PASSWORD_PATH, Mixins::Common::EndpointsV1::UPDATE_TOTP_PATH, Mixins::Common::EndpointsV1::UPDATE_USER_EMAIL_ENCHANTEDLINK_PATH, Mixins::Common::EndpointsV1::UPDATE_USER_EMAIL_MAGICLINK_PATH, Mixins::Common::EndpointsV1::UPDATE_USER_EMAIL_OTP_PATH, Mixins::Common::EndpointsV1::UPDATE_USER_PHONE_MAGICLINK_PATH, Mixins::Common::EndpointsV1::UPDATE_USER_PHONE_OTP_PATH, Mixins::Common::EndpointsV1::VALIDATE_SESSION_PATH, Mixins::Common::EndpointsV1::VERIFY_CODE_AUTH_PATH, Mixins::Common::EndpointsV1::VERIFY_ENCHANTEDLINK_AUTH_PATH, Mixins::Common::EndpointsV1::VERIFY_MAGICLINK_AUTH_PATH, Mixins::Common::EndpointsV1::VERIFY_TOTP_PATH
Constants included from Mixins::Common
Mixins::Common::COOKIE_DATA_NAME, Mixins::Common::DEFAULT_BASE_URL, Mixins::Common::DEFAULT_JWT_VALIDATION_LEEWAY, Mixins::Common::DEFAULT_TIMEOUT_SECONDS, Mixins::Common::PHONE_REGEX, Mixins::Common::REDIRECT_LOCATION_COOKIE_NAME, Mixins::Common::REFRESH_SESSION_COOKIE_NAME, Mixins::Common::REFRESH_SESSION_TOKEN_NAME, Mixins::Common::SESSION_COOKIE_NAME, Mixins::Common::SESSION_TOKEN_NAME
Instance Method Summary collapse
- #otp_sign_in(method: nil, login_id: nil, login_options: nil, refresh_token: nil, provider_id: nil, template_id: nil, sso_app_id: nil) ⇒ Object
- #otp_sign_up(method: nil, login_id: nil, user: {}, provider_id: nil, template_id: nil) ⇒ Object
- #otp_sign_up_or_in(method: nil, login_id: nil, login_options: nil, provider_id: nil, template_id: nil, sso_app_id: nil) ⇒ Object
- #otp_update_user_email(login_id: nil, email: nil, refresh_token: nil, add_to_login_ids: false, on_merge_use_existing: false, provider_id: nil, template_id: nil) ⇒ Object
- #otp_update_user_phone(method: nil, login_id: nil, phone: nil, refresh_token: nil, add_to_login_ids: false, on_merge_use_existing: false, provider_id: nil, template_id: nil) ⇒ Object
- #otp_verify_code(method: nil, login_id: nil, code: nil) ⇒ Object
Methods included from Mixins::Validation
#validate_code, #validate_email, #validate_login_id, #validate_password, #validate_phone, #validate_redirect_url, #validate_refresh_token_not_nil, #validate_scim_group_id, #validate_tenant, #validate_tenants, #validate_token_not_empty, #validate_user_id, #verify_provider
Methods included from Mixins::Common
#deep_copy, #get_method_string
Instance Method Details
#otp_sign_in(method: nil, login_id: nil, login_options: nil, refresh_token: nil, provider_id: nil, template_id: nil, sso_app_id: nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/descope/api/v1/auth/otp.rb', line 13 def otp_sign_in(method: nil, login_id: nil, login_options: nil, refresh_token: nil, provider_id: nil, template_id: nil, sso_app_id: nil) # Sign in (log in) an existing user with the unique login_id you provide. # The login_id field is used to identify the user. It can be an email address or a phone number. # Provide the DeliveryMethod required for this user. If the login_id value cannot be used for the # DeliverMethod selected (for example, 'login_id = 4567qq445km' and 'DeliveryMethod = email') validate_login_id(login_id) uri = otp_compose_signin_url(method) body = otp_compose_signin_body(login_id, , provider_id, template_id, sso_app_id) res = post(uri, body, {}, refresh_token) extract_masked_address(res, method) end |
#otp_sign_up(method: nil, login_id: nil, user: {}, provider_id: nil, template_id: nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/descope/api/v1/auth/otp.rb', line 26 def otp_sign_up(method: nil, login_id: nil, user: {}, provider_id: nil, template_id: nil) # Sign up (create) a new user using their email or phone number. # The login_id field is used to identify the user. It can be an email address or a phone number. # Choose a delivery method for OTP verification, for example email, SMS, or Voice. # (optional) Include additional user metadata that you wish to preserve. validate_login_id(login_id) unless adjust_and_verify_delivery_method(method, login_id, user) raise Descope::AuthException.new('Could not verify delivery method', code: 400) end uri = otp_compose_signup_url(method) body = otp_compose_signup_body(method, login_id, user, provider_id, template_id) res = post(uri, body) extract_masked_address(res, method) end |
#otp_sign_up_or_in(method: nil, login_id: nil, login_options: nil, provider_id: nil, template_id: nil, sso_app_id: nil) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/descope/api/v1/auth/otp.rb', line 43 def otp_sign_up_or_in(method: nil, login_id: nil, login_options: nil, provider_id: nil, template_id: nil, sso_app_id: nil) # Sign_up_or_in lets you handle both sign up and sign in with a single call. # The login_id field is used to identify the user. It can be an email address or a phone number. # Sign-up_or_in will first determine if login_id is a new or existing end user. # If login_id is new, a new end user user will be created and then authenticated using the # OTP DeliveryMethod specified. # If login_id exists, the end user will be authenticated using the OTP DeliveryMethod specified. validate_login_id(login_id) uri = otp_compose_sign_up_or_in_url(method) body = otp_compose_signin_body(login_id, , provider_id, template_id, sso_app_id) res = post(uri, body) extract_masked_address(res, method) end |
#otp_update_user_email(login_id: nil, email: nil, refresh_token: nil, add_to_login_ids: false, on_merge_use_existing: false, provider_id: nil, template_id: nil) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/descope/api/v1/auth/otp.rb', line 71 def otp_update_user_email(login_id: nil, email: nil, refresh_token: nil, add_to_login_ids: false, on_merge_use_existing: false, provider_id: nil, template_id: nil) # Update the email address of an end user, after verifying the authenticity of the end user using OTP. validate_login_id(login_id) validate_email(email) request_params = { loginId: login_id, email:, addToLoginIDs: add_to_login_ids, onMergeUseExisting: on_merge_use_existing } request_params[:providerId] = provider_id if provider_id request_params[:templateId] = template_id if template_id res = post(UPDATE_USER_EMAIL_OTP_PATH, request_params, {}, refresh_token) extract_masked_address(res, DeliveryMethod::EMAIL) end |
#otp_update_user_phone(method: nil, login_id: nil, phone: nil, refresh_token: nil, add_to_login_ids: false, on_merge_use_existing: false, provider_id: nil, template_id: nil) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/descope/api/v1/auth/otp.rb', line 88 def otp_update_user_phone( method: nil, login_id: nil, phone: nil, refresh_token: nil, add_to_login_ids: false, on_merge_use_existing: false, provider_id: nil, template_id: nil ) # Update the phone number of an existing end user, after verifying the authenticity of the end user using OTP validate_login_id(login_id) validate_phone(method, phone) uri = otp_compose_update_phone_url(method) request_params = { loginId: login_id, phone:, addToLoginIDs: add_to_login_ids, onMergeUseExisting: on_merge_use_existing } request_params[:providerId] = provider_id if provider_id request_params[:templateId] = template_id if template_id res = post(uri, request_params, {}, refresh_token) extract_masked_address(res, method) end |
#otp_verify_code(method: nil, login_id: nil, code: nil) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/descope/api/v1/auth/otp.rb', line 58 def otp_verify_code(method: nil, login_id: nil, code: nil) validate_login_id(login_id) uri = otp_compose_verify_code_url(method) request_params = { loginId: login_id, code: } res = post(uri, request_params) = res.fetch(COOKIE_DATA_NAME, nil) || res.fetch('cookies', {}) = .fetch(REFRESH_SESSION_COOKIE_NAME, nil) || res.fetch('refreshJwt', nil) generate_jwt_response(response_body: res, refresh_cookie:) end |