-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add external connection endpoints (#61)
* add external connection endpoints * bump minor version
- Loading branch information
1 parent
861986d
commit b605f3a
Showing
8 changed files
with
386 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
stytch/src/main/kotlin/com/stytch/java/b2b/api/ssoexternal/SSOExternal.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
package com.stytch.java.b2b.api.ssoexternal | ||
|
||
// !!! | ||
// 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.ssoexternal.CreateConnectionRequest | ||
import com.stytch.java.b2b.models.ssoexternal.CreateConnectionRequestOptions | ||
import com.stytch.java.b2b.models.ssoexternal.CreateConnectionResponse | ||
import com.stytch.java.b2b.models.ssoexternal.UpdateConnectionRequest | ||
import com.stytch.java.b2b.models.ssoexternal.UpdateConnectionRequestOptions | ||
import com.stytch.java.b2b.models.ssoexternal.UpdateConnectionResponse | ||
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 External { | ||
/** | ||
* Create a new External SSO Connection. | ||
*/ | ||
public suspend fun createConnection( | ||
data: CreateConnectionRequest, | ||
methodOptions: CreateConnectionRequestOptions? = null, | ||
): StytchResult<CreateConnectionResponse> | ||
|
||
/** | ||
* Create a new External SSO Connection. | ||
*/ | ||
public fun createConnection( | ||
data: CreateConnectionRequest, | ||
methodOptions: CreateConnectionRequestOptions? = null, | ||
callback: (StytchResult<CreateConnectionResponse>) -> Unit, | ||
) | ||
|
||
/** | ||
* Create a new External SSO Connection. | ||
*/ | ||
public fun createConnectionCompletable( | ||
data: CreateConnectionRequest, | ||
methodOptions: CreateConnectionRequestOptions? = null, | ||
): CompletableFuture<StytchResult<CreateConnectionResponse>> | ||
|
||
/** | ||
* Updates an existing External SSO connection. | ||
*/ | ||
public suspend fun updateConnection( | ||
data: UpdateConnectionRequest, | ||
methodOptions: UpdateConnectionRequestOptions? = null, | ||
): StytchResult<UpdateConnectionResponse> | ||
|
||
/** | ||
* Updates an existing External SSO connection. | ||
*/ | ||
public fun updateConnection( | ||
data: UpdateConnectionRequest, | ||
methodOptions: UpdateConnectionRequestOptions? = null, | ||
callback: (StytchResult<UpdateConnectionResponse>) -> Unit, | ||
) | ||
|
||
/** | ||
* Updates an existing External SSO connection. | ||
*/ | ||
public fun updateConnectionCompletable( | ||
data: UpdateConnectionRequest, | ||
methodOptions: UpdateConnectionRequestOptions? = null, | ||
): CompletableFuture<StytchResult<UpdateConnectionResponse>> | ||
} | ||
|
||
internal class ExternalImpl( | ||
private val httpClient: HttpClient, | ||
private val coroutineScope: CoroutineScope, | ||
) : External { | ||
private val moshi = Moshi.Builder().add(InstantAdapter()).build() | ||
|
||
override suspend fun createConnection( | ||
data: CreateConnectionRequest, | ||
methodOptions: CreateConnectionRequestOptions?, | ||
): StytchResult<CreateConnectionResponse> = | ||
withContext(Dispatchers.IO) { | ||
var headers = emptyMap<String, String>() | ||
methodOptions?.let { | ||
headers = methodOptions.addHeaders(headers) | ||
} | ||
|
||
val asJson = moshi.adapter(CreateConnectionRequest::class.java).toJson(data) | ||
httpClient.post("/v1/b2b/sso/external/${data.organizationId}", asJson, headers) | ||
} | ||
|
||
override fun createConnection( | ||
data: CreateConnectionRequest, | ||
methodOptions: CreateConnectionRequestOptions?, | ||
callback: (StytchResult<CreateConnectionResponse>) -> Unit, | ||
) { | ||
coroutineScope.launch { | ||
callback(createConnection(data, methodOptions)) | ||
} | ||
} | ||
|
||
override fun createConnectionCompletable( | ||
data: CreateConnectionRequest, | ||
methodOptions: CreateConnectionRequestOptions?, | ||
): CompletableFuture<StytchResult<CreateConnectionResponse>> = | ||
coroutineScope.async { | ||
createConnection(data, methodOptions) | ||
}.asCompletableFuture() | ||
|
||
override suspend fun updateConnection( | ||
data: UpdateConnectionRequest, | ||
methodOptions: UpdateConnectionRequestOptions?, | ||
): StytchResult<UpdateConnectionResponse> = | ||
withContext(Dispatchers.IO) { | ||
var headers = emptyMap<String, String>() | ||
methodOptions?.let { | ||
headers = methodOptions.addHeaders(headers) | ||
} | ||
|
||
val asJson = moshi.adapter(UpdateConnectionRequest::class.java).toJson(data) | ||
httpClient.put("/v1/b2b/sso/external/${data.organizationId}/connections/${data.connectionId}", asJson, headers) | ||
} | ||
|
||
override fun updateConnection( | ||
data: UpdateConnectionRequest, | ||
methodOptions: UpdateConnectionRequestOptions?, | ||
callback: (StytchResult<UpdateConnectionResponse>) -> Unit, | ||
) { | ||
coroutineScope.launch { | ||
callback(updateConnection(data, methodOptions)) | ||
} | ||
} | ||
|
||
override fun updateConnectionCompletable( | ||
data: UpdateConnectionRequest, | ||
methodOptions: UpdateConnectionRequestOptions?, | ||
): CompletableFuture<StytchResult<UpdateConnectionResponse>> = | ||
coroutineScope.async { | ||
updateConnection(data, methodOptions) | ||
}.asCompletableFuture() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.