Module: Descope::Api::V1::Auth::MagicLink

Includes:
Mixins::Common::EndpointsV1, Mixins::Common::EndpointsV2, Mixins::Validation
Included in:
Descope::Api::V1::Auth
Defined in:
lib/descope/api/v1/auth/magiclink.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

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



26
27
28
29
30
31
32
33
# File 'lib/descope/api/v1/auth/magiclink.rb', line 26

def (method: nil, login_id: nil, uri: nil, login_options: nil, refresh_token: nil)
  ()
  validate_refresh_token_provided(, refresh_token)
  body = (, uri, )
  uri = (method)
  res = post(uri, body, {}, refresh_token)
  extract_masked_address(res, method)
end


13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/descope/api/v1/auth/magiclink.rb', line 13

def (method: nil, login_id: nil, uri: nil, user: {}, provider_id: nil, template_id: nil)
  # Sign-up new end user by sending a magic link via email
  # @see https://docs.descope.com/api/openapi/magiclink/operation/SignUpMagicLinkEmail/
  ()

  body = (, uri, user, method)
  body[:providerId] = provider_id if provider_id
  body[:templateId] = template_id if template_id
  uri = (method)
  res = post(uri, body)
  extract_masked_address(res, method)
end


35
36
37
38
39
40
# File 'lib/descope/api/v1/auth/magiclink.rb', line 35

def (method: nil, login_id: nil, uri: nil, login_options: nil)
  body = (, uri, )
  uri = (method)
  res = post(uri, body)
  extract_masked_address(res, method)
end


50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/descope/api/v1/auth/magiclink.rb', line 50

def magiclink_update_user_email(login_id: nil, email: nil, uri: nil, add_to_login_ids: nil, on_merge_use_existing: nil, provider_id: nil, template_id: nil, template_options: nil, refresh_token: nil)
  ()
  validate_token_not_empty(refresh_token)
  validate_email(email)

  body = magiclink_compose_update_user_email_body(, email, uri, , on_merge_use_existing)
  body[:providerId] = provider_id if provider_id
  body[:templateId] = template_id if template_id
  body[:templateOptions] = template_options if template_options
  uri = UPDATE_USER_EMAIL_MAGICLINK_PATH
  res = post(uri, body, {}, refresh_token)
  extract_masked_address(res, Descope::Mixins::Common::DeliveryMethod::EMAIL)
end


64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/descope/api/v1/auth/magiclink.rb', line 64

def magiclink_update_user_phone(login_id: nil, phone: nil, uri: nil, add_to_login_ids: nil, on_merge_use_existing: nil, provider_id: nil, template_id: nil, template_options: nil, method: nil, refresh_token: nil)
  ()
  validate_token_not_empty(refresh_token)
  validate_phone(method, phone)

  body = magiclink_compose_update_user_phone_body(, phone, uri, , on_merge_use_existing)
  body[:providerId] = provider_id if provider_id
  body[:templateId] = template_id if template_id
  body[:templateOptions] = template_options if template_options
  uri = UPDATE_USER_PHONE_MAGICLINK_PATH
  res = post(uri, body, {}, refresh_token)
  extract_masked_address(res, Descope::Mixins::Common::DeliveryMethod::SMS)
end


42
43
44
45
46
47
48
# File 'lib/descope/api/v1/auth/magiclink.rb', line 42

def magiclink_verify_token(token = nil)
  validate_token_not_empty(token)
  res = post(VERIFY_MAGICLINK_AUTH_PATH, { token: })
  cookies = res.fetch(COOKIE_DATA_NAME, nil) || res.fetch('cookies', {})
  refresh_cookie = cookies.fetch(REFRESH_SESSION_COOKIE_NAME, nil) || res.fetch('refreshJwt', nil)
  generate_jwt_response(response_body: res, refresh_cookie:)
end