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, telemetry_id: 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, sha_512_config: nil, scrypt_config: nil, pbkdf_2_config: nil, name: nil, trusted_metadata: nil, untrusted_metadata: nil, roles: nil, preserve_existing_sessions: nil, mfa_phone_number: nil, set_phone_number_verified: nil, external_id: nil) ⇒ Object
Warning: This endpoint marks the Member’s email address as verified.
-
#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
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, telemetry_id: 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-policy) 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 Member is required to complete MFA to log in to the Organization, 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. You may also use the organization_slug or organization_external_id here as a convenience. 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 characters, 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 Member 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. - telemetry_id
-
If the ‘telemetry_id` is passed, as part of this request, Stytch will call the [Fingerprint Lookup API](stytch.com/docs/fraud/api/fingerprint-lookup) and store the associated fingerprints and IPGEO information for the Member. Your workspace must be enabled for Device Fingerprinting to use this feature. 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. The token has a default expiry of 10 minutes. 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). - primary_required
-
Information about the primary authentication requirements of the Organization. The type of this field is nilable
PrimaryRequired(object). - member_device
-
If a valid ‘telemetry_id` was passed in the request and the [Fingerprint Lookup API](stytch.com/docs/fraud/api/fingerprint-lookup) returned results, the `member_device` response field will contain information about the member’s device attributes. The type of this field is nilable
DeviceInfo(object).
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/stytch/b2b_passwords.rb', line 343 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, telemetry_id: 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? request[:telemetry_id] = telemetry_id unless telemetry_id.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, sha_512_config: nil, scrypt_config: nil, pbkdf_2_config: nil, name: nil, trusted_metadata: nil, untrusted_metadata: nil, roles: nil, preserve_existing_sessions: nil, mfa_phone_number: nil, set_phone_number_verified: nil, external_id: nil) ⇒ Object
Warning: This endpoint marks the Member’s email address as verified. Do not use this endpoint unless the user has already verified their email address in your application.
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, SHA-512, 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.
If you are using **cross-organization passwords**, i.e. allowing an end user to share the same password across all of their Organizations, call this method separately for each ‘organization_id` associated with the given `email_address` to ensure the password is set across all of their Organizations.
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`, `argon_2id`, `md_5`, `sha_1`, `sha_512`, 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. You may also use the organization_slug or organization_external_id here as a convenience. 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). - sha_512_config
-
Optional parameters for SHA-512 hash types. The type of this field is nilable
SHA512Config(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. - mfa_phone_number
-
The Member’s phone number. A Member may only have one phone number. The phone number should be in E.164 format (i.e. +1XXXXXXXXXX). The type of this field is nilable
String. - set_phone_number_verified
-
Whether to set the user’s phone number as verified. This is a dangerous field. This flag should only be set if you can attest that
the user owns the phone number in question.The type of this field is nilable
Boolean. - external_id
-
If a new member is created, this will set an identifier that can be used in most API calls where a ‘member_id` is expected. This is a string consisting of alphanumeric, `.`, `_`, `-`, or `|` characters with a maximum length of 128 characters. External IDs must be unique within an organization, but may be reused across different organizations in the same project. Note that if a member already exists, this field will be ignored. 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. - 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.
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/stytch/b2b_passwords.rb', line 193 def migrate( email_address:, hash:, hash_type:, organization_id:, md_5_config: nil, argon_2_config: nil, sha_1_config: nil, sha_512_config: nil, scrypt_config: nil, pbkdf_2_config: nil, name: nil, trusted_metadata: nil, untrusted_metadata: nil, roles: nil, preserve_existing_sessions: nil, mfa_phone_number: nil, set_phone_number_verified: nil, external_id: 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[:sha_512_config] = sha_512_config unless sha_512_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? request[:mfa_phone_number] = mfa_phone_number unless mfa_phone_number.nil? request[:set_phone_number_verified] = set_phone_number_verified unless set_phone_number_verified.nil? request[:external_id] = external_id unless external_id.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 on the [Passwords Policy page](stytch.com/dashboard/password-strength-config) in the Stytch Dashboard.
## 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 characters, 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/guides/passwords/strength-policy) is the default option which offers a high level of sophistication. We also offer [LUDS](stytch.com/docs/b2b/guides/passwords/strength-policy). 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/guides/passwords/strength-policy). 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/b2b/guides/passwords/strength-policy). The type of this field is nilable
ZxcvbnFeedback(object).
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/stytch/b2b_passwords.rb', line 81 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 |