Class: StytchB2B::Passwords
- Inherits:
-
Object
- Object
- StytchB2B::Passwords
- Includes:
- Stytch::RequestHelper
- Defined in:
- lib/stytch/b2b_passwords.rb
Defined Under Namespace
Classes: Discovery, Email, ExistingPassword, Sessions
Instance Attribute Summary collapse
-
#discovery ⇒ Object
readonly
Returns the value of attribute discovery.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#existing_password ⇒ Object
readonly
Returns the value of attribute existing_password.
-
#sessions ⇒ Object
readonly
Returns the value of attribute sessions.
Instance Method Summary collapse
-
#authenticate(organization_id:, email_address:, password:, session_token: nil, session_duration_minutes: nil, session_jwt: nil, session_custom_claims: nil, locale: nil, intermediate_session_token: nil) ⇒ Object
Authenticate a member with their email address and password.
-
#initialize(connection) ⇒ Passwords
constructor
A new instance of Passwords.
-
#migrate(email_address:, hash:, hash_type:, organization_id:, md_5_config: nil, argon_2_config: nil, sha_1_config: nil, scrypt_config: nil, pbkdf_2_config: nil, name: nil, trusted_metadata: nil, untrusted_metadata: nil, roles: nil, preserve_existing_sessions: nil) ⇒ Object
Adds an existing password to a member’s email that doesn’t have a password yet.
-
#strength_check(password:, email_address: nil) ⇒ Object
This API allows you to check whether the user’s provided password is valid, and to provide feedback to the user on how to increase the strength of their password.
Methods included from Stytch::RequestHelper
#delete_request, #get_request, #post_request, #put_request, #request_with_query_params
Constructor Details
#initialize(connection) ⇒ Passwords
Returns a new instance of Passwords.
16 17 18 19 20 21 22 23 |
# File 'lib/stytch/b2b_passwords.rb', line 16 def initialize(connection) @connection = connection @email = StytchB2B::Passwords::Email.new(@connection) @sessions = StytchB2B::Passwords::Sessions.new(@connection) @existing_password = StytchB2B::Passwords::ExistingPassword.new(@connection) @discovery = StytchB2B::Passwords::Discovery.new(@connection) end |
Instance Attribute Details
#discovery ⇒ Object (readonly)
Returns the value of attribute discovery.
14 15 16 |
# File 'lib/stytch/b2b_passwords.rb', line 14 def discovery @discovery end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
14 15 16 |
# File 'lib/stytch/b2b_passwords.rb', line 14 def email @email end |
#existing_password ⇒ Object (readonly)
Returns the value of attribute existing_password.
14 15 16 |
# File 'lib/stytch/b2b_passwords.rb', line 14 def existing_password @existing_password end |
#sessions ⇒ Object (readonly)
Returns the value of attribute sessions.
14 15 16 |
# File 'lib/stytch/b2b_passwords.rb', line 14 def sessions @sessions end |
Instance Method Details
#authenticate(organization_id:, email_address:, password:, session_token: nil, session_duration_minutes: nil, session_jwt: nil, session_custom_claims: nil, locale: nil, intermediate_session_token: nil) ⇒ Object
Authenticate a member with their email address and password. This endpoint verifies that the member has a password currently set, and that the entered password is correct.
If you have breach detection during authentication enabled in your [password strength policy](stytch.com/docs/b2b/guides/passwords/strength-policies) and the member’s credentials have appeared in the HaveIBeenPwned dataset, this endpoint will return a ‘member_reset_password` error even if the member enters a correct password. We force a password reset in this case to ensure that the member is the legitimate owner of the email address and not a malicious actor abusing the compromised credentials.
If the is required to complete MFA to log in to the, the returned value of ‘member_authenticated` will be `false`, and an `intermediate_session_token` will be returned. The `intermediate_session_token` can be passed into the [OTP SMS Authenticate endpoint](stytch.com/docs/b2b/api/authenticate-otp-sms) to complete the MFA step and acquire a full member session. The `session_duration_minutes` and `session_custom_claims` parameters will be ignored.
If a valid ‘session_token` or `session_jwt` is passed in, the Member will not be required to complete an MFA step.
Parameters:
- organization_id
-
Globally unique UUID that identifies a specific Organization. The ‘organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. The type of this field is
String
. - email_address
-
The email address of the Member. The type of this field is
String
. - password
-
The password to authenticate, reset, or set for the first time. Any UTF8 character is allowed, e.g. spaces, emojis, non-English characers, etc. The type of this field is
String
. - session_token
-
A secret token for a given Stytch Session. The type of this field is nilable
String
. - session_duration_minutes
-
Set the session lifetime to be this many minutes from now. This will start a new session if one doesn’t already exist, returning both an opaque ‘session_token` and `session_jwt` for this session. Remember that the `session_jwt` will have a fixed lifetime of five minutes regardless of the underlying session duration, and will need to be refreshed over time.
This value must be a minimum of 5 and a maximum of 527040 minutes (366 days).
If a ‘session_token` or `session_jwt` is provided then a successful authentication will continue to extend the session this many minutes.
If the ‘session_duration_minutes` parameter is not specified, a Stytch session will be created with a 60 minute duration. If you don’t want to use the Stytch session product, you can ignore the session fields in the response. The type of this field is nilable
Integer
. - session_jwt
-
The JSON Web Token (JWT) for a given Stytch Session. The type of this field is nilable
String
. - session_custom_claims
-
Add a custom claims map to the Session being authenticated. Claims are only created if a Session is initialized by providing a value in ‘session_duration_minutes`. Claims will be included on the Session object and in the JWT. To update a key in an existing Session, supply a new value. To delete a key, supply a null value. Custom claims made with reserved claims (`iss`, `sub`, `aud`, `exp`, `nbf`, `iat`, `jti`) will be ignored. Total custom claims size cannot exceed four kilobytes. The type of this field is nilable
object
. - locale
-
If the needs to complete an MFA step, and the Member has a phone number, this endpoint will pre-emptively send a one-time passcode (OTP) to the Member’s phone number. The locale argument will be used to determine which language to use when sending the passcode.
Parameter is a [IETF BCP 47 language tag](www.w3.org/International/articles/language-tags/), e.g. ‘“en”`.
Currently supported languages are English (‘“en”`), Spanish (`“es”`), and Brazilian Portuguese (`“pt-br”`); if no value is provided, the copy defaults to English.
Request support for additional languages [here](docs.google.com/forms/d/e/1FAIpQLScZSpAu_m2AmLXRT3F3kap-s_mcV6UTBitYn6CdyWP0-o7YjQ/viewform?usp=sf_link“)!
The type of this field is nilable +AuthenticateRequestLocale+ (string enum).
- intermediate_session_token
-
Adds this primary authentication factor to the intermediate session token. If the resulting set of factors satisfies the organization’s primary authentication requirements and MFA requirements, the intermediate session token will be consumed and converted to a member session. If not, the same intermediate session token will be returned. The type of this field is nilable
String
.
Returns:
An object with the following fields:
- request_id
-
Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue. The type of this field is
String
. - member_id
-
Globally unique UUID that identifies a specific Member. The type of this field is
String
. - organization_id
-
Globally unique UUID that identifies a specific Organization. The ‘organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. The type of this field is
String
. - member
-
The [Member object](stytch.com/docs/b2b/api/member-object) The type of this field is
Member
(object
). - session_token
-
A secret token for a given Stytch Session. The type of this field is
String
. - session_jwt
-
The JSON Web Token (JWT) for a given Stytch Session. The type of this field is
String
. - organization
-
The [Organization object](stytch.com/docs/b2b/api/organization-object). The type of this field is
Organization
(object
). - intermediate_session_token
-
The returned Intermediate Session Token contains a password factor associated with the Member. If this value is non-empty, the member must complete an MFA step to finish logging in to the Organization. The token can be used with the [OTP SMS Authenticate endpoint](stytch.com/docs/b2b/api/authenticate-otp-sms), [TOTP Authenticate endpoint](stytch.com/docs/b2b/api/authenticate-totp), or [Recovery Codes Recover endpoint](stytch.com/docs/b2b/api/recovery-codes-recover) to complete an MFA flow and log in to the Organization. Password factors are not transferable between Organizations, so the intermediate session token is not valid for use with discovery endpoints. The type of this field is
String
. - member_authenticated
-
Indicates whether the Member is fully authenticated. If false, the Member needs to complete an MFA step to log in to the Organization. The type of this field is
Boolean
. - status_code
-
The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors. The type of this field is
Integer
. - member_session
-
The [Session object](stytch.com/docs/b2b/api/session-object). The type of this field is nilable
MemberSession
(object
). - mfa_required
-
Information about the MFA requirements of the Organization and the Member’s options for fulfilling MFA. The type of this field is nilable
MfaRequired
(object
).
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/stytch/b2b_passwords.rb', line 303 def authenticate( organization_id:, email_address:, password:, session_token: nil, session_duration_minutes: nil, session_jwt: nil, session_custom_claims: nil, locale: nil, intermediate_session_token: nil ) headers = {} request = { organization_id: organization_id, email_address: email_address, password: password } request[:session_token] = session_token unless session_token.nil? request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil? request[:session_jwt] = session_jwt unless session_jwt.nil? request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil? request[:locale] = locale unless locale.nil? request[:intermediate_session_token] = intermediate_session_token unless intermediate_session_token.nil? post_request('/v1/b2b/passwords/authenticate', request, headers) end |
#migrate(email_address:, hash:, hash_type:, organization_id:, md_5_config: nil, argon_2_config: nil, sha_1_config: nil, scrypt_config: nil, pbkdf_2_config: nil, name: nil, trusted_metadata: nil, untrusted_metadata: nil, roles: nil, preserve_existing_sessions: nil) ⇒ Object
Adds an existing password to a member’s email that doesn’t have a password yet. We support migrating members from passwords stored with bcrypt, scrypt, argon2, MD-5, SHA-1, and PBKDF2. This endpoint has a rate limit of 100 requests per second.
The member’s email will be marked as verified when you use this endpoint.
Parameters:
- email_address
-
The email address of the Member. The type of this field is
String
. - hash
-
The password hash. For a Scrypt or PBKDF2 hash, the hash needs to be a base64 encoded string. The type of this field is
String
. - hash_type
-
The password hash used. Currently ‘bcrypt`, `scrypt`, `argon_2i`, `argon2_id`, `md_5`, `sha_1`, and `pbkdf_2` are supported. The type of this field is
MigrateRequestHashType
(string enum). - organization_id
-
Globally unique UUID that identifies a specific Organization. The ‘organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. The type of this field is
String
. - md_5_config
-
Optional parameters for MD-5 hash types. The type of this field is nilable
MD5Config
(object
). - argon_2_config
-
Required parameters if the argon2 hex form, as opposed to the encoded form, is supplied. The type of this field is nilable
Argon2Config
(object
). - sha_1_config
-
Optional parameters for SHA-1 hash types. The type of this field is nilable
SHA1Config
(object
). - scrypt_config
-
Required parameters if the scrypt is not provided in a **PHC encoded form**. The type of this field is nilable
ScryptConfig
(object
). - pbkdf_2_config
-
Required additional parameters for PBKDF2 hash keys. Note that we use the SHA-256 by default, please contact [[email protected]]([email protected]) if you use another hashing function. The type of this field is nilable
PBKDF2Config
(object
). - name
-
The name of the Member. Each field in the name object is optional. The type of this field is nilable
String
. - trusted_metadata
-
An arbitrary JSON object for storing application-specific data or identity-provider-specific data. The type of this field is nilable
object
. - untrusted_metadata
-
An arbitrary JSON object of application-specific data. These fields can be edited directly by the frontend SDK, and should not be used to store critical information. See the [Metadata resource](stytch.com/docs/b2b/api/metadata) for complete field behavior details. The type of this field is nilable
object
. - roles
-
Roles to explicitly assign to this Member.
Will completely replace any existing explicitly assigned roles. See the
[RBAC guide](https://stytch.com/docs/b2b/guides/rbac/role-assignment) for more information about role assignment.
If a Role is removed from a Member, and the Member is also implicitly assigned this Role from an SSO connection
or an SSO group, we will by default revoke any existing sessions for the Member that contain any SSO
authentication factors with the affected connection ID. You can preserve these sessions by passing in the
`preserve_existing_sessions` parameter with a value of `true`.
The type of this field is nilable list of +String+.
- preserve_existing_sessions
-
Whether to preserve existing sessions when explicit Roles that are revoked are also implicitly assigned by SSO connection or SSO group. Defaults to ‘false` - that is, existing Member Sessions that contain SSO authentication factors with the affected SSO connection IDs will be revoked. The type of this field is nilable
Boolean
.
Returns:
An object with the following fields:
- request_id
-
Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue. The type of this field is
String
. - member_id
-
Globally unique UUID that identifies a specific Member. The type of this field is
String
. - member_created
-
A flag indicating ‘true` if a new Member object was created and `false` if the Member object already existed. The type of this field is
Boolean
. - member
-
The [Member object](stytch.com/docs/b2b/api/member-object) The type of this field is
Member
(object
). - organization
-
The [Organization object](stytch.com/docs/b2b/api/organization-object). The type of this field is
Organization
(object
). - status_code
-
The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors. The type of this field is
Integer
.
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/stytch/b2b_passwords.rb', line 170 def migrate( email_address:, hash:, hash_type:, organization_id:, md_5_config: nil, argon_2_config: nil, sha_1_config: nil, scrypt_config: nil, pbkdf_2_config: nil, name: nil, trusted_metadata: nil, untrusted_metadata: nil, roles: nil, preserve_existing_sessions: nil ) headers = {} request = { email_address: email_address, hash: hash, hash_type: hash_type, organization_id: organization_id } request[:md_5_config] = md_5_config unless md_5_config.nil? request[:argon_2_config] = argon_2_config unless argon_2_config.nil? request[:sha_1_config] = sha_1_config unless sha_1_config.nil? request[:scrypt_config] = scrypt_config unless scrypt_config.nil? request[:pbkdf_2_config] = pbkdf_2_config unless pbkdf_2_config.nil? request[:name] = name unless name.nil? request[:trusted_metadata] = unless .nil? request[:untrusted_metadata] = unless .nil? request[:roles] = roles unless roles.nil? request[:preserve_existing_sessions] = preserve_existing_sessions unless preserve_existing_sessions.nil? post_request('/v1/b2b/passwords/migrate', request, headers) end |
#strength_check(password:, email_address: nil) ⇒ Object
This API allows you to check whether the user’s provided password is valid, and to provide feedback to the user on how to increase the strength of their password.
This endpoint adapts to your Project’s password strength configuration. If you’re using [zxcvbn](stytch.com/docs/guides/passwords/strength-policy), the default, your passwords are considered valid if the strength score is >= 3. If you’re using [LUDS](stytch.com/docs/guides/passwords/strength-policy), your passwords are considered valid if they meet the requirements that you’ve set with Stytch. You may update your password strength configuration in the [stytch dashboard](stytch.com/dashboard/password-strength-config).
## Password feedback The zxcvbn_feedback and luds_feedback objects contains relevant fields for you to relay feedback to users that failed to create a strong enough password.
If you’re using [zxcvbn](stytch.com/docs/guides/passwords/strength-policy), the feedback object will contain warning and suggestions for any password that does not meet the [zxcvbn](stytch.com/docs/guides/passwords/strength-policy) strength requirements. You can return these strings directly to the user to help them craft a strong password.
If you’re using [LUDS](stytch.com/docs/guides/passwords/strength-policy), the feedback object will contain a collection of fields that the user failed or passed. You’ll want to prompt the user to create a password that meets all requirements that they failed.
Parameters:
- password
-
The password to authenticate, reset, or set for the first time. Any UTF8 character is allowed, e.g. spaces, emojis, non-English characers, etc. The type of this field is
String
. - email_address
-
The email address of the Member. The type of this field is nilable
String
.
Returns:
An object with the following fields:
- request_id
-
Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue. The type of this field is
String
. - valid_password
-
Returns ‘true` if the password passes our password validation. We offer two validation options, [zxcvbn](stytch.com/docs/passwords#strength-requirements) is the default option which offers a high level of sophistication. We also offer [LUDS](stytch.com/docs/passwords#strength-requirements). If an email address is included in the call we also require that the password hasn’t been compromised using built-in breach detection powered by [HaveIBeenPwned](haveibeenpwned.com/) The type of this field is
Boolean
. - score
-
The score of the password determined by [zxcvbn](github.com/dropbox/zxcvbn). Values will be between 1 and 4, a 3 or greater is required to pass validation. The type of this field is
Integer
. - breached_password
-
Returns ‘true` if the password has been breached. Powered by [HaveIBeenPwned](haveibeenpwned.com/). The type of this field is
Boolean
. - strength_policy
-
The strength policy type enforced, either ‘zxcvbn` or `luds`. The type of this field is
String
. - breach_detection_on_create
-
Will return ‘true` if breach detection will be evaluated. By default this option is enabled. This option can be disabled by contacting [[email protected]]([email protected]?subject=Password%20strength%20configuration). If this value is false then `breached_password` will always be `false` as well. The type of this field is
Boolean
. - status_code
-
The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors. The type of this field is
Integer
. - luds_feedback
-
Feedback for how to improve the password’s strength using [luds](stytch.com/docs/passwords#strength-requirements). The type of this field is nilable
LudsFeedback
(object
). - zxcvbn_feedback
-
Feedback for how to improve the password’s strength using [zxcvbn](stytch.com/docs/passwords#strength-requirements). The type of this field is nilable
ZxcvbnFeedback
(object
).
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/stytch/b2b_passwords.rb', line 78 def strength_check( password:, email_address: nil ) headers = {} request = { password: password } request[:email_address] = email_address unless email_address.nil? post_request('/v1/b2b/passwords/strength_check', request, headers) end |