com.stytch.java.b2b.StytchB2BClient.kt Maven / Gradle / Ivy
package com.stytch.java.b2b
// !!!
// WARNING: This file is autogenerated
// Only modify code within MANUAL() sections
// or your changes may be overwritten later!
// !!!
import com.stytch.java.b2b.api.discovery.Discovery
import com.stytch.java.b2b.api.discovery.DiscoveryImpl
import com.stytch.java.b2b.api.magiclinks.MagicLinks
import com.stytch.java.b2b.api.magiclinks.MagicLinksImpl
import com.stytch.java.b2b.api.oauth.OAuth
import com.stytch.java.b2b.api.oauth.OAuthImpl
import com.stytch.java.b2b.api.organizations.Organizations
import com.stytch.java.b2b.api.organizations.OrganizationsImpl
import com.stytch.java.b2b.api.otp.OTPs
import com.stytch.java.b2b.api.otp.OTPsImpl
import com.stytch.java.b2b.api.passwords.Passwords
import com.stytch.java.b2b.api.passwords.PasswordsImpl
import com.stytch.java.b2b.api.rbac.RBAC
import com.stytch.java.b2b.api.rbac.RBACImpl
import com.stytch.java.b2b.api.recoverycodes.RecoveryCodes
import com.stytch.java.b2b.api.recoverycodes.RecoveryCodesImpl
import com.stytch.java.b2b.api.scim.SCIM
import com.stytch.java.b2b.api.scim.SCIMImpl
import com.stytch.java.b2b.api.sessions.Sessions
import com.stytch.java.b2b.api.sessions.SessionsImpl
import com.stytch.java.b2b.api.sso.SSO
import com.stytch.java.b2b.api.sso.SSOImpl
import com.stytch.java.b2b.api.totps.TOTPs
import com.stytch.java.b2b.api.totps.TOTPsImpl
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.common.PolicyCache
import com.stytch.java.consumer.api.m2m.M2M
import com.stytch.java.consumer.api.m2m.M2MImpl
import com.stytch.java.consumer.api.project.Project
import com.stytch.java.consumer.api.project.ProjectImpl
import com.stytch.java.http.HttpClient
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import org.jose4j.jwk.HttpsJwks
public object StytchB2BClient {
private lateinit var httpClient: HttpClient
private lateinit var httpsJwks: HttpsJwks
private lateinit var jwtOptions: JwtOptions
private lateinit var policyCache: PolicyCache
@JvmStatic
public lateinit var discovery: Discovery
@JvmStatic
public lateinit var m2m: M2M
@JvmStatic
public lateinit var magicLinks: MagicLinks
@JvmStatic
public lateinit var oauth: OAuth
@JvmStatic
public lateinit var otps: OTPs
@JvmStatic
public lateinit var organizations: Organizations
@JvmStatic
public lateinit var passwords: Passwords
@JvmStatic
public lateinit var project: Project
@JvmStatic
public lateinit var rbac: RBAC
@JvmStatic
public lateinit var recoveryCodes: RecoveryCodes
@JvmStatic
public lateinit var scim: SCIM
@JvmStatic
public lateinit var sso: SSO
@JvmStatic
public lateinit var sessions: Sessions
@JvmStatic
public lateinit var totps: TOTPs
@JvmStatic
public fun configure(
projectId: String,
secret: String,
) {
val baseUrl = getBaseUrl(projectId)
httpClient =
HttpClient(
baseUrl = baseUrl,
projectId = projectId,
secret = secret,
)
jwtOptions =
JwtOptions(
audience = projectId,
issuer = "stytch.com/$projectId",
type = "JWT",
)
val coroutineScope = CoroutineScope(SupervisorJob())
httpsJwks = HttpsJwks("$baseUrl/v1/b2b/sessions/jwks/$projectId")
policyCache = PolicyCache(RBACImpl(httpClient, coroutineScope))
discovery = DiscoveryImpl(httpClient, coroutineScope)
m2m = M2MImpl(httpClient, coroutineScope, httpsJwks, jwtOptions)
magicLinks = MagicLinksImpl(httpClient, coroutineScope)
oauth = OAuthImpl(httpClient, coroutineScope)
otps = OTPsImpl(httpClient, coroutineScope)
organizations = OrganizationsImpl(httpClient, coroutineScope)
passwords = PasswordsImpl(httpClient, coroutineScope)
project = ProjectImpl(httpClient, coroutineScope)
rbac = RBACImpl(httpClient, coroutineScope)
recoveryCodes = RecoveryCodesImpl(httpClient, coroutineScope)
scim = SCIMImpl(httpClient, coroutineScope)
sso = SSOImpl(httpClient, coroutineScope)
sessions = SessionsImpl(httpClient, coroutineScope, httpsJwks, jwtOptions, policyCache)
totps = TOTPsImpl(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
}
}