com.stytch.java.b2b.api.passwordssession.PasswordsSession.kt Maven / Gradle / Ivy
package com.stytch.java.b2b.api.passwordssession
// !!!
// 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.passwordssession.ResetRequest
import com.stytch.java.b2b.models.passwordssession.ResetResponse
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 Sessions {
/**
* Reset the's password using their existing session. The endpoint will error if the session does not contain an
* authentication factor that has been issued within the last 5 minutes. Either `session_token` or `session_jwt` should be
* provided.
*
* Note that a successful password reset via an existing session will revoke all active sessions for the `member_id`,
* except for the one used during the reset flow.
*/
public suspend fun reset(data: ResetRequest): StytchResult
/**
* Reset the's password using their existing session. The endpoint will error if the session does not contain an
* authentication factor that has been issued within the last 5 minutes. Either `session_token` or `session_jwt` should be
* provided.
*
* Note that a successful password reset via an existing session will revoke all active sessions for the `member_id`,
* except for the one used during the reset flow.
*/
public fun reset(
data: ResetRequest,
callback: (StytchResult) -> Unit,
)
/**
* Reset the's password using their existing session. The endpoint will error if the session does not contain an
* authentication factor that has been issued within the last 5 minutes. Either `session_token` or `session_jwt` should be
* provided.
*
* Note that a successful password reset via an existing session will revoke all active sessions for the `member_id`,
* except for the one used during the reset flow.
*/
public fun resetCompletable(data: ResetRequest): CompletableFuture>
}
internal class SessionsImpl(
private val httpClient: HttpClient,
private val coroutineScope: CoroutineScope,
) : Sessions {
private val moshi = Moshi.Builder().add(InstantAdapter()).build()
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/session/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()
}