Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCIM Support #29

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ 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
Expand Down Expand Up @@ -70,6 +72,9 @@ public object StytchB2BClient {
@JvmStatic
public lateinit var recoveryCodes: RecoveryCodes

@JvmStatic
public lateinit var scim: SCIM

@JvmStatic
public lateinit var sso: SSO

Expand Down Expand Up @@ -110,6 +115,7 @@ public object StytchB2BClient {
passwords = PasswordsImpl(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)
Expand Down
27 changes: 27 additions & 0 deletions stytch/src/main/kotlin/com/stytch/java/b2b/api/scim/SCIM.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.stytch.java.b2b.api.scim

// !!!
// 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.api.scimconnections.Connections
import com.stytch.java.b2b.api.scimconnections.ConnectionsImpl
import com.stytch.java.common.InstantAdapter
import com.stytch.java.http.HttpClient
import kotlinx.coroutines.CoroutineScope

public interface SCIM {
public val connections: Connections
}

internal class SCIMImpl(
private val httpClient: HttpClient,
private val coroutineScope: CoroutineScope,
) : SCIM {
private val moshi = Moshi.Builder().add(InstantAdapter()).build()

override val connections: Connections = ConnectionsImpl(httpClient, coroutineScope)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,335 @@
package com.stytch.java.b2b.api.scimconnections

// !!!
// WARNING: This file is autogenerated
// Only modify code within MANUAL() sections
// or your changes may be overwritten later!
// !!!

import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import com.stytch.java.b2b.models.scimconnections.CreateRequest
import com.stytch.java.b2b.models.scimconnections.CreateResponse
import com.stytch.java.b2b.models.scimconnections.DeleteRequest
import com.stytch.java.b2b.models.scimconnections.DeleteResponse
import com.stytch.java.b2b.models.scimconnections.GetRequest
import com.stytch.java.b2b.models.scimconnections.GetResponse
import com.stytch.java.b2b.models.scimconnections.RotateCancelRequest
import com.stytch.java.b2b.models.scimconnections.RotateCancelResponse
import com.stytch.java.b2b.models.scimconnections.RotateCompleteRequest
import com.stytch.java.b2b.models.scimconnections.RotateCompleteResponse
import com.stytch.java.b2b.models.scimconnections.RotateStartRequest
import com.stytch.java.b2b.models.scimconnections.RotateStartResponse
import com.stytch.java.b2b.models.scimconnections.UpdateRequest
import com.stytch.java.b2b.models.scimconnections.UpdateResponse
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 Connections {
/**
* Update a SCIM Connection. /%}
*/
public suspend fun update(data: UpdateRequest): StytchResult<UpdateResponse>

/**
* Update a SCIM Connection. /%}
*/
public fun update(
data: UpdateRequest,
callback: (StytchResult<UpdateResponse>) -> Unit,
)

/**
* Update a SCIM Connection. /%}
*/
public fun updateCompletable(data: UpdateRequest): CompletableFuture<StytchResult<UpdateResponse>>

/**
* Deletes a SCIM Connection. /%}
*/
public suspend fun delete(data: DeleteRequest): StytchResult<DeleteResponse>

/**
* Deletes a SCIM Connection. /%}
*/
public fun delete(
data: DeleteRequest,
callback: (StytchResult<DeleteResponse>) -> Unit,
)

/**
* Deletes a SCIM Connection. /%}
*/
public fun deleteCompletable(data: DeleteRequest): CompletableFuture<StytchResult<DeleteResponse>>

/**
* Start a SCIM token rotation. /%}
*/
public suspend fun rotateStart(data: RotateStartRequest): StytchResult<RotateStartResponse>

/**
* Start a SCIM token rotation. /%}
*/
public fun rotateStart(
data: RotateStartRequest,
callback: (StytchResult<RotateStartResponse>) -> Unit,
)

/**
* Start a SCIM token rotation. /%}
*/
public fun rotateStartCompletable(data: RotateStartRequest): CompletableFuture<StytchResult<RotateStartResponse>>

/**
* Completes a SCIM token rotation. This will complete the current token rotation process and update the active token to
* be the new token supplied in the [start SCIM token rotation](https://stytch.com/docs/b2b/api/scim-rotate-token-start)
* response. /%}
*/
public suspend fun rotateComplete(data: RotateCompleteRequest): StytchResult<RotateCompleteResponse>

/**
* Completes a SCIM token rotation. This will complete the current token rotation process and update the active token to
* be the new token supplied in the [start SCIM token rotation](https://stytch.com/docs/b2b/api/scim-rotate-token-start)
* response. /%}
*/
public fun rotateComplete(
data: RotateCompleteRequest,
callback: (StytchResult<RotateCompleteResponse>) -> Unit,
)

/**
* Completes a SCIM token rotation. This will complete the current token rotation process and update the active token to
* be the new token supplied in the [start SCIM token rotation](https://stytch.com/docs/b2b/api/scim-rotate-token-start)
* response. /%}
*/
public fun rotateCompleteCompletable(data: RotateCompleteRequest): CompletableFuture<StytchResult<RotateCompleteResponse>>

/**
* Cancel a SCIM token rotation. This will cancel the current token rotation process, keeping the original token active.
* /%}
*/
public suspend fun rotateCancel(data: RotateCancelRequest): StytchResult<RotateCancelResponse>

/**
* Cancel a SCIM token rotation. This will cancel the current token rotation process, keeping the original token active.
* /%}
*/
public fun rotateCancel(
data: RotateCancelRequest,
callback: (StytchResult<RotateCancelResponse>) -> Unit,
)

/**
* Cancel a SCIM token rotation. This will cancel the current token rotation process, keeping the original token active.
* /%}
*/
public fun rotateCancelCompletable(data: RotateCancelRequest): CompletableFuture<StytchResult<RotateCancelResponse>>

/**
* Create a new SCIM Connection. /%}
*/
public suspend fun create(data: CreateRequest): StytchResult<CreateResponse>

/**
* Create a new SCIM Connection. /%}
*/
public fun create(
data: CreateRequest,
callback: (StytchResult<CreateResponse>) -> Unit,
)

/**
* Create a new SCIM Connection. /%}
*/
public fun createCompletable(data: CreateRequest): CompletableFuture<StytchResult<CreateResponse>>

/**
* Get SCIM Connections. /%}
*/
public suspend fun get(data: GetRequest): StytchResult<GetResponse>

/**
* Get SCIM Connections. /%}
*/
public fun get(
data: GetRequest,
callback: (StytchResult<GetResponse>) -> Unit,
)

/**
* Get SCIM Connections. /%}
*/
public fun getCompletable(data: GetRequest): CompletableFuture<StytchResult<GetResponse>>
}

internal class ConnectionsImpl(
private val httpClient: HttpClient,
private val coroutineScope: CoroutineScope,
) : Connections {
private val moshi = Moshi.Builder().add(InstantAdapter()).build()

override suspend fun update(data: UpdateRequest): StytchResult<UpdateResponse> =
withContext(Dispatchers.IO) {
var headers = emptyMap<String, String>()

val asJson = moshi.adapter(UpdateRequest::class.java).toJson(data)
httpClient.put("/v1/b2b/scim/${data.organizationId}/connections/${data.connectionId}", asJson, headers)
}

override fun update(
data: UpdateRequest,
callback: (StytchResult<UpdateResponse>) -> Unit,
) {
coroutineScope.launch {
callback(update(data))
}
}

override fun updateCompletable(data: UpdateRequest): CompletableFuture<StytchResult<UpdateResponse>> =
coroutineScope.async {
update(data)
}.asCompletableFuture()

override suspend fun delete(data: DeleteRequest): StytchResult<DeleteResponse> =
withContext(Dispatchers.IO) {
var headers = emptyMap<String, String>()

httpClient.delete("/v1/b2b/scim/${data.organizationId}/connections/${data.connectionId}", headers)
}

override fun delete(
data: DeleteRequest,
callback: (StytchResult<DeleteResponse>) -> Unit,
) {
coroutineScope.launch {
callback(delete(data))
}
}

override fun deleteCompletable(data: DeleteRequest): CompletableFuture<StytchResult<DeleteResponse>> =
coroutineScope.async {
delete(data)
}.asCompletableFuture()

override suspend fun rotateStart(data: RotateStartRequest): StytchResult<RotateStartResponse> =
withContext(Dispatchers.IO) {
var headers = emptyMap<String, String>()

val asJson = moshi.adapter(RotateStartRequest::class.java).toJson(data)
httpClient.post("/v1/b2b/scim/${data.organizationId}/connections/${data.connectionId}/rotate/start", asJson, headers)
}

override fun rotateStart(
data: RotateStartRequest,
callback: (StytchResult<RotateStartResponse>) -> Unit,
) {
coroutineScope.launch {
callback(rotateStart(data))
}
}

override fun rotateStartCompletable(data: RotateStartRequest): CompletableFuture<StytchResult<RotateStartResponse>> =
coroutineScope.async {
rotateStart(data)
}.asCompletableFuture()

override suspend fun rotateComplete(data: RotateCompleteRequest): StytchResult<RotateCompleteResponse> =
withContext(Dispatchers.IO) {
var headers = emptyMap<String, String>()

val asJson = moshi.adapter(RotateCompleteRequest::class.java).toJson(data)
httpClient.post("/v1/b2b/scim/${data.organizationId}/connections/${data.connectionId}/rotate/complete", asJson, headers)
}

override fun rotateComplete(
data: RotateCompleteRequest,
callback: (StytchResult<RotateCompleteResponse>) -> Unit,
) {
coroutineScope.launch {
callback(rotateComplete(data))
}
}

override fun rotateCompleteCompletable(data: RotateCompleteRequest): CompletableFuture<StytchResult<RotateCompleteResponse>> =
coroutineScope.async {
rotateComplete(data)
}.asCompletableFuture()

override suspend fun rotateCancel(data: RotateCancelRequest): StytchResult<RotateCancelResponse> =
withContext(Dispatchers.IO) {
var headers = emptyMap<String, String>()

val asJson = moshi.adapter(RotateCancelRequest::class.java).toJson(data)
httpClient.post("/v1/b2b/scim/${data.organizationId}/connections/${data.connectionId}/rotate/cancel", asJson, headers)
}

override fun rotateCancel(
data: RotateCancelRequest,
callback: (StytchResult<RotateCancelResponse>) -> Unit,
) {
coroutineScope.launch {
callback(rotateCancel(data))
}
}

override fun rotateCancelCompletable(data: RotateCancelRequest): CompletableFuture<StytchResult<RotateCancelResponse>> =
coroutineScope.async {
rotateCancel(data)
}.asCompletableFuture()

override suspend fun create(data: CreateRequest): StytchResult<CreateResponse> =
withContext(Dispatchers.IO) {
var headers = emptyMap<String, String>()

val asJson = moshi.adapter(CreateRequest::class.java).toJson(data)
httpClient.post("/v1/b2b/scim/${data.organizationId}/connections", asJson, headers)
}

override fun create(
data: CreateRequest,
callback: (StytchResult<CreateResponse>) -> Unit,
) {
coroutineScope.launch {
callback(create(data))
}
}

override fun createCompletable(data: CreateRequest): CompletableFuture<StytchResult<CreateResponse>> =
coroutineScope.async {
create(data)
}.asCompletableFuture()

override suspend fun get(data: GetRequest): StytchResult<GetResponse> =
withContext(Dispatchers.IO) {
var headers = emptyMap<String, String>()

val asJson = moshi.adapter(GetRequest::class.java).toJson(data)
val type = Types.newParameterizedType(Map::class.java, String::class.java, Any::class.java)
val adapter: JsonAdapter<Map<String, Any>> = moshi.adapter(type)
val asMap = adapter.fromJson(asJson) ?: emptyMap()
httpClient.get("/v1/b2b/scim/${data.organizationId}/connections", asMap, headers)
}

override fun get(
data: GetRequest,
callback: (StytchResult<GetResponse>) -> Unit,
) {
coroutineScope.launch {
callback(get(data))
}
}

override fun getCompletable(data: GetRequest): CompletableFuture<StytchResult<GetResponse>> =
coroutineScope.async {
get(data)
}.asCompletableFuture()
}
Loading