All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.stytch.java.consumer.StytchClient.kt Maven / Gradle / Ivy

There is a newer version: 6.0.0
Show newest version
package com.stytch.java.consumer

// !!!
// WARNING: This file is autogenerated
// Only modify code within MANUAL() sections
// or your changes may be overwritten later!
// !!!
import com.stytch.java.common.BASE_LIVE_URL
import com.stytch.java.common.BASE_TEST_URL
import com.stytch.java.common.JwtOptions
import com.stytch.java.consumer.api.cryptowallets.CryptoWallets
import com.stytch.java.consumer.api.cryptowallets.CryptoWalletsImpl
import com.stytch.java.consumer.api.m2m.M2M
import com.stytch.java.consumer.api.m2m.M2MImpl
import com.stytch.java.consumer.api.magiclinks.MagicLinks
import com.stytch.java.consumer.api.magiclinks.MagicLinksImpl
import com.stytch.java.consumer.api.oauth.OAuth
import com.stytch.java.consumer.api.oauth.OAuthImpl
import com.stytch.java.consumer.api.otp.OTPs
import com.stytch.java.consumer.api.otp.OTPsImpl
import com.stytch.java.consumer.api.passwords.Passwords
import com.stytch.java.consumer.api.passwords.PasswordsImpl
import com.stytch.java.consumer.api.project.Project
import com.stytch.java.consumer.api.project.ProjectImpl
import com.stytch.java.consumer.api.sessions.Sessions
import com.stytch.java.consumer.api.sessions.SessionsImpl
import com.stytch.java.consumer.api.totps.TOTPs
import com.stytch.java.consumer.api.totps.TOTPsImpl
import com.stytch.java.consumer.api.users.Users
import com.stytch.java.consumer.api.users.UsersImpl
import com.stytch.java.consumer.api.webauthn.WebAuthn
import com.stytch.java.consumer.api.webauthn.WebAuthnImpl
import com.stytch.java.http.HttpClient
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import org.jose4j.jwk.HttpsJwks

public class StytchClient(projectId: String, secret: String) {
    private val coroutineScope = CoroutineScope(SupervisorJob())
    private val baseUrl = getBaseUrl(projectId)
    private val httpClient: HttpClient =
        HttpClient(
            baseUrl = baseUrl,
            projectId = projectId,
            secret = secret,
        )
    private val httpsJwks = HttpsJwks("$baseUrl/v1/sessions/jwks/$projectId")
    private val jwtOptions: JwtOptions =
        JwtOptions(
            audience = projectId,
            issuer = "stytch.com/$projectId",
            type = "JWT",
        )

    @JvmField
    public val cryptoWallets: CryptoWallets = CryptoWalletsImpl(httpClient, coroutineScope)

    @JvmField
    public val m2m: M2M = M2MImpl(httpClient, coroutineScope, httpsJwks, jwtOptions)

    @JvmField
    public val magicLinks: MagicLinks = MagicLinksImpl(httpClient, coroutineScope)

    @JvmField
    public val oauth: OAuth = OAuthImpl(httpClient, coroutineScope)

    @JvmField
    public val otps: OTPs = OTPsImpl(httpClient, coroutineScope)

    @JvmField
    public val passwords: Passwords = PasswordsImpl(httpClient, coroutineScope)

    @JvmField
    public val project: Project = ProjectImpl(httpClient, coroutineScope)

    @JvmField
    public val sessions: Sessions = SessionsImpl(httpClient, coroutineScope, httpsJwks, jwtOptions)

    @JvmField
    public val totps: TOTPs = TOTPsImpl(httpClient, coroutineScope)

    @JvmField
    public val users: Users = UsersImpl(httpClient, coroutineScope)

    @JvmField
    public val webauthn: WebAuthn = WebAuthnImpl(httpClient, coroutineScope)

    /**
     * Resolve the base URL for the Stytch API environment.
     */
    private fun getBaseUrl(projectId: String): String =
        when (projectId.startsWith("project-test")) {
            true -> BASE_TEST_URL
            false -> BASE_LIVE_URL
        }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy