
com.stytch.java.b2b.api.passwordsdiscoveryemail.PasswordsDiscoveryEmail.kt Maven / Gradle / Ivy
package com.stytch.java.b2b.api.passwordsdiscoveryemail
// !!!
// WARNING: This file is autogenerated
// Only modify code within MANUAL() sections
// or your changes may be overwritten later!
// !!!
import com.squareup.moshi.Moshi
import com.stytch.java.b2b.models.passwordsdiscoveryemail.ResetRequest
import com.stytch.java.b2b.models.passwordsdiscoveryemail.ResetResponse
import com.stytch.java.b2b.models.passwordsdiscoveryemail.ResetStartRequest
import com.stytch.java.b2b.models.passwordsdiscoveryemail.ResetStartResponse
import com.stytch.java.common.InstantAdapter
import com.stytch.java.common.StytchResult
import com.stytch.java.http.HttpClient
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.future.asCompletableFuture
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.concurrent.CompletableFuture
public interface Email {
/**
* Initiates a password reset for the email address provided, when cross-org passwords are enabled. This will trigger an
* email to be sent to the address, containing a magic link that will allow them to set a new password and authenticate.
*
* This endpoint adapts to your Project's password strength configuration.
* If you're using [zxcvbn](https://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](https://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](https://stytch.com/dashboard/password-strength-config).
*/
public suspend fun resetStart(data: ResetStartRequest): StytchResult
/**
* Initiates a password reset for the email address provided, when cross-org passwords are enabled. This will trigger an
* email to be sent to the address, containing a magic link that will allow them to set a new password and authenticate.
*
* This endpoint adapts to your Project's password strength configuration.
* If you're using [zxcvbn](https://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](https://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](https://stytch.com/dashboard/password-strength-config).
*/
public fun resetStart(
data: ResetStartRequest,
callback: (StytchResult) -> Unit,
)
/**
* Initiates a password reset for the email address provided, when cross-org passwords are enabled. This will trigger an
* email to be sent to the address, containing a magic link that will allow them to set a new password and authenticate.
*
* This endpoint adapts to your Project's password strength configuration.
* If you're using [zxcvbn](https://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](https://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](https://stytch.com/dashboard/password-strength-config).
*/
public fun resetStartCompletable(data: ResetStartRequest): CompletableFuture>
/**
* Reset the password associated with an email and start an intermediate session. This endpoint checks that the password
* reset token is valid, hasn’t expired, or already been used.
*
* The provided password needs to meet the project's password strength requirements, which can be checked in advance with
* the password strength endpoint. If the token and password are accepted, the password is securely stored for future
* authentication and the user is authenticated.
*
* Resetting a password will start an intermediate session and return a list of discovered organizations the session can
* be exchanged into.
*/
public suspend fun reset(data: ResetRequest): StytchResult
/**
* Reset the password associated with an email and start an intermediate session. This endpoint checks that the password
* reset token is valid, hasn’t expired, or already been used.
*
* The provided password needs to meet the project's password strength requirements, which can be checked in advance with
* the password strength endpoint. If the token and password are accepted, the password is securely stored for future
* authentication and the user is authenticated.
*
* Resetting a password will start an intermediate session and return a list of discovered organizations the session can
* be exchanged into.
*/
public fun reset(
data: ResetRequest,
callback: (StytchResult) -> Unit,
)
/**
* Reset the password associated with an email and start an intermediate session. This endpoint checks that the password
* reset token is valid, hasn’t expired, or already been used.
*
* The provided password needs to meet the project's password strength requirements, which can be checked in advance with
* the password strength endpoint. If the token and password are accepted, the password is securely stored for future
* authentication and the user is authenticated.
*
* Resetting a password will start an intermediate session and return a list of discovered organizations the session can
* be exchanged into.
*/
public fun resetCompletable(data: ResetRequest): CompletableFuture>
}
internal class EmailImpl(
private val httpClient: HttpClient,
private val coroutineScope: CoroutineScope,
) : Email {
private val moshi = Moshi.Builder().add(InstantAdapter()).build()
override suspend fun resetStart(data: ResetStartRequest): StytchResult =
withContext(Dispatchers.IO) {
var headers = emptyMap()
val asJson = moshi.adapter(ResetStartRequest::class.java).toJson(data)
httpClient.post("/v1/b2b/passwords/discovery/email/reset/start", asJson, headers)
}
override fun resetStart(
data: ResetStartRequest,
callback: (StytchResult) -> Unit,
) {
coroutineScope.launch {
callback(resetStart(data))
}
}
override fun resetStartCompletable(data: ResetStartRequest): CompletableFuture> =
coroutineScope.async {
resetStart(data)
}.asCompletableFuture()
override suspend fun reset(data: ResetRequest): StytchResult =
withContext(Dispatchers.IO) {
var headers = emptyMap()
val asJson = moshi.adapter(ResetRequest::class.java).toJson(data)
httpClient.post("/v1/b2b/passwords/discovery/email/reset", asJson, headers)
}
override fun reset(
data: ResetRequest,
callback: (StytchResult) -> Unit,
) {
coroutineScope.launch {
callback(reset(data))
}
}
override fun resetCompletable(data: ResetRequest): CompletableFuture> =
coroutineScope.async {
reset(data)
}.asCompletableFuture()
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy