Module: Descope::Api::V1::Auth::Password

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

#get_password_policy(refresh_token = nil) ⇒ Object



73
74
75
76
# File 'lib/descope/api/v1/auth/password.rb', line 73

def get_password_policy(refresh_token = nil)
  # Get the configured password policy for the project.
  get(PASSWORD_POLICY_PATH, {}, {}, refresh_token)
end

#password_replace(login_id: nil, old_password: nil, new_password: nil) ⇒ Object



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

def password_replace(login_id: nil, old_password: nil, new_password: nil)
  # Replace an existing user's password with a new password.
  ()
  validate_password(old_password)
  validate_password(new_password)
  request_params = {
    loginId: ,
    oldPassword: old_password,
    newPassword: new_password
  }
  post(REPLACE_PASSWORD_PATH, request_params)
end

#password_reset(login_id: nil, redirect_url: nil, provider_id: nil, template_id: nil) ⇒ Object



78
79
80
81
82
83
84
85
# File 'lib/descope/api/v1/auth/password.rb', line 78

def password_reset(login_id: nil, redirect_url: nil, provider_id: nil, template_id: nil)
  #  Sends a password reset prompt to the user with the given
  #  login_id according to the password settings defined in the Descope console.
  # NOTE: The user must be verified according to the configured password reset method.
  ()
  post(SEND_RESET_PASSWORD_PATH,
       loginId: , redirectUrl: redirect_url, providerId: provider_id, templateId: template_id)
end

#password_sign_in(login_id: nil, password: nil, sso_app_id: nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/descope/api/v1/auth/password.rb', line 30

def (login_id: nil, password: nil, sso_app_id: nil)
  # Sign-In an existing user utilizing password authentication. This endpoint will return the user's JWT..
  # Return dict in the format
  #  {"jwts": [], "user": "", "firstSeen": "", "error": ""}
  # Includes all the jwts tokens (session token, refresh token), token claims, and user information
  ()
  validate_password(password)
  request_params = {
    loginId: ,
    password:,
    ssoAppId: sso_app_id
  }
  res = post(, request_params)
  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

#password_sign_up(login_id: nil, password: nil, user: nil) ⇒ Object



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

def (login_id: nil, password: nil, user: nil)
  # Sign up (create) a new user using a login ID and password.
  # (optional) Include additional user metadata that you wish to save.
  ()
  validate_password(password)
  request_params = {
    loginId: ,
    password:
  }

  request_params[:user] = password_user_compose_update_body(**user) unless user.nil?
  res = post(, request_params)
  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

#password_update(login_id: nil, new_password: nil, refresh_token: nil) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/descope/api/v1/auth/password.rb', line 61

def password_update(login_id: nil, new_password: nil, refresh_token: nil)
  # Update an existing user's password with a new password.
  ()
  validate_password(new_password)
  validate_refresh_token_not_nil(refresh_token)
  request_params = {
    loginId: ,
    newPassword: new_password
  }
  post(UPDATE_PASSWORD_PATH, request_params, {}, refresh_token)
end