Module: Descope::Api::V1::Auth::EnchantedLink

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



67
68
69
70
71
72
73
# File 'lib/descope/api/v1/auth/enchantedlink.rb', line 67

def enchanted_link_get_session(pending_ref = nil)
  # @see https://docs.descope.com/api/openapi/enchantedlink/operation/GetEnchantedLinkSession/
  res = post(GET_SESSION_ENCHANTEDLINK_AUTH_PATH, { pendingRef: pending_ref })
  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


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

def (login_id: nil, uri: nil, login_options: nil, refresh_token: nil)
  # Sign-in existing user by sending an enchanted link via email.
  # @see https://docs.descope.com/api/openapi/enchantedlink/operation/SignInEnchantedLinkEmail/
  ()
  validate_refresh_token_provided(, refresh_token)
  body = (, uri, )
  uri = 
  post(uri, body, nil, refresh_token)
end


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/descope/api/v1/auth/enchantedlink.rb', line 23

def (login_id: nil, uri: nil, user: {})
  # Sign-up new end user by sending an enchanted link via email
  # @see https://docs.descope.com/api/openapi/enchantedlink/operation/SignUpEnchantedLink/

  unless adjust_and_verify_delivery_method(Descope::Mixins::Common::DeliveryMethod::EMAIL, , user)
    raise Descope::ArgumentException.new(
      'Invalid delivery method',
      code: 400
    )
  end

  body = (, uri, user)
  uri = 
  post(uri, body)
end


39
40
41
42
43
44
# File 'lib/descope/api/v1/auth/enchantedlink.rb', line 39

def (login_id: nil, uri: nil, login_options: nil)
  # @see https://docs.descope.com/api/openapi/enchantedlink/operation/SignUpOrInEnchantedLinkEmail/
  body = (, uri, )
  uri = 
  post(uri, body)
end


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/descope/api/v1/auth/enchantedlink.rb', line 46

def enchanted_link_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 = enchanted_link_compose_update_user_email_body(
    , email, , on_merge_use_existing
  )
  body[:redirectUrl] = uri
  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_ENCHANTEDLINK_PATH
  post(uri, body, {}, refresh_token)
end


62
63
64
65
# File 'lib/descope/api/v1/auth/enchantedlink.rb', line 62

def enchanted_link_verify_token(token = nil)
  validate_token_not_empty(token)
  post(VERIFY_ENCHANTEDLINK_AUTH_PATH, { token: })
end