Fixes for nested query parsing and MFA route authentication types

This commit is contained in:
Jake Barnby
2024-02-07 19:24:01 +13:00
parent 2766e15eab
commit d42be7aa66
6 changed files with 2 additions and 189 deletions
@@ -1,24 +0,0 @@
import io.appwrite.Client;
import io.appwrite.coroutines.CoroutineCallback;
import io.appwrite.services.Users;
import io.appwrite.enums.AuthenticatorProvider;
Client client = new Client(context)
.setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
.setProject("5df5acd0d48c2"); // Your project ID
Users users = new Users(client);
users.deleteAuthenticator(
"[USER_ID]",
AuthenticatorProvider.TOTP,
"[OTP]",
new CoroutineCallback<>((result, error) -> {
if (error != null) {
error.printStackTrace();
return;
}
Log.d("Appwrite", result.toString());
})
);
@@ -1,21 +0,0 @@
import io.appwrite.Client;
import io.appwrite.coroutines.CoroutineCallback;
import io.appwrite.services.Users;
Client client = new Client(context)
.setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
.setProject("5df5acd0d48c2"); // Your project ID
Users users = new Users(client);
users.listProviders(
"[USER_ID]",
new CoroutineCallback<>((result, error) -> {
if (error != null) {
error.printStackTrace();
return;
}
Log.d("Appwrite", result.toString());
})
);
@@ -1,16 +0,0 @@
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Users
import io.appwrite.enums.AuthenticatorProvider
val client = Client(context)
.setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
.setProject("5df5acd0d48c2") // Your project ID
val users = Users(client)
val response = users.deleteAuthenticator(
userId = "[USER_ID]",
provider = AuthenticatorProvider.TOTP,
otp = "[OTP]",
)
@@ -1,13 +0,0 @@
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Users
val client = Client(context)
.setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
.setProject("5df5acd0d48c2") // Your project ID
val users = Users(client)
val response = users.listProviders(
userId = "[USER_ID]",
)
@@ -161,7 +161,7 @@ data class Session(
* Returns a list of active session factors.
*/
@SerializedName("factors")
val factors: Long,
val factors: List<Any>,
/**
* Secret used to authenticate the user. Only included if the request was made with an API key
@@ -231,7 +231,7 @@ data class Session(
countryCode = map["countryCode"] as String,
countryName = map["countryName"] as String,
current = map["current"] as Boolean,
factors = (map["factors"] as Number).toLong(),
factors = map["factors"] as List<Any>,
secret = map["secret"] as String,
)
}
@@ -1,113 +0,0 @@
package io.appwrite.services
import android.net.Uri
import io.appwrite.Client
import io.appwrite.models.*
import io.appwrite.enums.*
import io.appwrite.exceptions.AppwriteException
import io.appwrite.extensions.classOf
import okhttp3.Cookie
import java.io.File
/**
* The Users service allows you to manage your project users.
**/
class Users(client: Client) : Service(client) {
/**
* Delete Authenticator
*
*
*
* @param userId User ID.
* @param provider Provider.
* @param otp Valid verification token.
* @return [io.appwrite.models.User<T>]
*/
suspend fun <T> deleteAuthenticator(
userId: String,
provider: AuthenticatorProvider,
otp: String,
nestedType: Class<T>,
): io.appwrite.models.User<T> {
val apiPath = "/users/{userId}/mfa/{provider}"
.replace("{userId}", userId)
.replace("{provider}", provider.value)
val apiParams = mutableMapOf<String, Any?>(
"otp" to otp,
)
val apiHeaders = mutableMapOf(
"content-type" to "application/json",
)
val converter: (Any) -> io.appwrite.models.User<T> = {
@Suppress("UNCHECKED_CAST")
io.appwrite.models.User.from(map = it as Map<String, Any>, nestedType)
}
return client.call(
"DELETE",
apiPath,
apiHeaders,
apiParams,
responseType = classOf(),
converter,
)
}
/**
* Delete Authenticator
*
*
*
* @param userId User ID.
* @param provider Provider.
* @param otp Valid verification token.
* @return [io.appwrite.models.User<T>]
*/
@Throws(AppwriteException::class)
suspend fun deleteAuthenticator(
userId: String,
provider: AuthenticatorProvider,
otp: String,
): io.appwrite.models.User<Map<String, Any>> = deleteAuthenticator(
userId,
provider,
otp,
nestedType = classOf(),
)
/**
* List Providers
*
*
*
* @param userId User ID.
* @return [io.appwrite.models.MfaProviders]
*/
suspend fun listProviders(
userId: String,
): io.appwrite.models.MfaProviders {
val apiPath = "/users/{userId}/providers"
.replace("{userId}", userId)
val apiParams = mutableMapOf<String, Any?>(
)
val apiHeaders = mutableMapOf(
"content-type" to "application/json",
)
val converter: (Any) -> io.appwrite.models.MfaProviders = {
@Suppress("UNCHECKED_CAST")
io.appwrite.models.MfaProviders.from(map = it as Map<String, Any>)
}
return client.call(
"GET",
apiPath,
apiHeaders,
apiParams,
responseType = io.appwrite.models.MfaProviders::class.java,
converter,
)
}
}