From 294b2f4b96eca998e08b5208cd1f9eb9e128fa83 Mon Sep 17 00:00:00 2001 From: Jan Gaebel Date: Tue, 15 Jun 2021 19:50:24 +0200 Subject: [PATCH 1/6] fix(auth): missing parameters --- .../kotlin/com/liftric/auth/jwt/AccessToken.kt | 7 ++++++- .../kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt | 2 ++ .../kotlin/com/liftric/auth/jwt/CognitoIdToken.kt | 3 +++ .../commonMain/kotlin/com/liftric/auth/jwt/IdToken.kt | 10 ++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/AccessToken.kt b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/AccessToken.kt index 1624e04..6fbd1e7 100644 --- a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/AccessToken.kt +++ b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/AccessToken.kt @@ -28,7 +28,12 @@ interface AccessToken { /** * JWT ID */ - val jti: String + val jti: String? + + /** + * JWT origin ID + */ + val originJti: String? /** * Not Before diff --git a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt index f5de645..bc875bd 100644 --- a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt +++ b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt @@ -13,6 +13,8 @@ data class CognitoAccessTokenClaims( override val iat: Long, override val iss: String, override val jti: String, + @SerialName("origin_jti") + override val originJti: String? = null, override val nbf: Long? = null, override val sub: String, @SerialName("auth_time") diff --git a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoIdToken.kt b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoIdToken.kt index a57e126..46b30d0 100644 --- a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoIdToken.kt +++ b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoIdToken.kt @@ -8,6 +8,9 @@ class InvalidCognitoIdTokenException(message:String): Exception(message) @Serializable(with = CustomAttributesSerializer::class) data class CognitoIdTokenClaims( override val sub: String? = null, + override val jti: String, + @SerialName("origin_jti") + override val originJti: String? = null, override val name: String? = null, override val givenName: String? = null, override val familyName: String? = null, diff --git a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/IdToken.kt b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/IdToken.kt index 790da19..dd3c07f 100644 --- a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/IdToken.kt +++ b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/IdToken.kt @@ -12,6 +12,16 @@ interface IdToken { */ val sub: String? + /** + * JWT ID + */ + val jti: String? + + /** + * JWT origin ID + */ + val originJti: String? + /** * Full name in displayable form including all name parts */ From 0cdbafd550320e26306a57504a1e263560047409 Mon Sep 17 00:00:00 2001 From: Jan Gaebel Date: Tue, 15 Jun 2021 20:00:39 +0200 Subject: [PATCH 2/6] fix(auth): custom serializer --- .../com/liftric/auth/jwt/CognitoIdToken.kt | 6 +++--- .../kotlin/com/liftric/auth/jwt/IdToken.kt | 20 +++++++++---------- .../com/liftric/auth/jwt/IdTokenSerializer.kt | 10 ++++++++++ 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoIdToken.kt b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoIdToken.kt index 46b30d0..4c957e0 100644 --- a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoIdToken.kt +++ b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoIdToken.kt @@ -8,9 +8,6 @@ class InvalidCognitoIdTokenException(message:String): Exception(message) @Serializable(with = CustomAttributesSerializer::class) data class CognitoIdTokenClaims( override val sub: String? = null, - override val jti: String, - @SerialName("origin_jti") - override val originJti: String? = null, override val name: String? = null, override val givenName: String? = null, override val familyName: String? = null, @@ -36,6 +33,9 @@ data class CognitoIdTokenClaims( override val cognitoUsername: String, override val exp: Long, override val eventId: String, + override val jti: String?, + @SerialName("origin_jti") + override val originJti: String? = null, override val iss: String, override val iat: Long, override val scope: String? = null, diff --git a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/IdToken.kt b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/IdToken.kt index dd3c07f..64eedc0 100644 --- a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/IdToken.kt +++ b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/IdToken.kt @@ -12,16 +12,6 @@ interface IdToken { */ val sub: String? - /** - * JWT ID - */ - val jti: String? - - /** - * JWT origin ID - */ - val originJti: String? - /** * Full name in displayable form including all name parts */ @@ -181,6 +171,16 @@ interface IdTokenExtension { */ val eventId: String + /** + * JWT ID + */ + val jti: String? + + /** + * JWT origin ID + */ + val originJti: String? + /** * Issuer */ diff --git a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/IdTokenSerializer.kt b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/IdTokenSerializer.kt index 2a6c5cf..f6bb768 100644 --- a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/IdTokenSerializer.kt +++ b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/IdTokenSerializer.kt @@ -103,6 +103,12 @@ internal object CustomAttributesSerializer : KSerializer { }?: run { throw SerializationException("Missing field event_id") } + val jti = filtersMap["jti"]?.let { + json.decodeFromJsonElement(String.serializer(), it) + } + val originJti = filtersMap["origin_jti"]?.let { + json.decodeFromJsonElement(String.serializer(), it) + } val iss = filtersMap["iss"]?.let { json.decodeFromJsonElement(String.serializer(), it) }?: run { @@ -168,6 +174,8 @@ internal object CustomAttributesSerializer : KSerializer { cognitoUsername, exp, eventId, + jti, + originJti, iss, iat, scope, @@ -206,6 +214,8 @@ internal object CustomAttributesSerializer : KSerializer { value.cognitoUsername.let { map["cognito:username"] = json.encodeToJsonElement(String.serializer(), it) } value.exp.let { map["exp"] = json.encodeToJsonElement(Long.serializer(), it) } value.eventId.let { map["event_id"] = json.encodeToJsonElement(String.serializer(), it) } + value.jti?.let { map["jti"] = json.encodeToJsonElement(String.serializer(), it) } + value.originJti?.let { map["origin_jti"] = json.encodeToJsonElement(String.serializer(), it) } value.iss.let { map["iss"] = json.encodeToJsonElement(String.serializer(), it) } value.iat.let { map["iat"] = json.encodeToJsonElement(Long.serializer(), it) } value.scope?.let { map["scope"] = json.encodeToJsonElement(String.serializer(), it) } From 11501963517800b7867510a79d261d1e2447496e Mon Sep 17 00:00:00 2001 From: Jan Gaebel Date: Tue, 15 Jun 2021 20:01:32 +0200 Subject: [PATCH 3/6] fix(auth): make optional --- .../kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt index bc875bd..fe24b44 100644 --- a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt +++ b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt @@ -12,7 +12,7 @@ data class CognitoAccessTokenClaims( override val exp: Long, override val iat: Long, override val iss: String, - override val jti: String, + override val jti: String?, @SerialName("origin_jti") override val originJti: String? = null, override val nbf: Long? = null, From 0c7400411be4aae03eec8b1a38ab987a67c1ef99 Mon Sep 17 00:00:00 2001 From: Jan Gaebel Date: Tue, 15 Jun 2021 20:02:13 +0200 Subject: [PATCH 4/6] fix(auth): default to null --- .../kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt | 2 +- .../commonMain/kotlin/com/liftric/auth/jwt/CognitoIdToken.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt index fe24b44..1203c9d 100644 --- a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt +++ b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt @@ -12,7 +12,7 @@ data class CognitoAccessTokenClaims( override val exp: Long, override val iat: Long, override val iss: String, - override val jti: String?, + override val jti: String? = null, @SerialName("origin_jti") override val originJti: String? = null, override val nbf: Long? = null, diff --git a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoIdToken.kt b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoIdToken.kt index 4c957e0..50efd81 100644 --- a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoIdToken.kt +++ b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoIdToken.kt @@ -33,7 +33,7 @@ data class CognitoIdTokenClaims( override val cognitoUsername: String, override val exp: Long, override val eventId: String, - override val jti: String?, + override val jti: String? = null, @SerialName("origin_jti") override val originJti: String? = null, override val iss: String, From e4061052f3a17658ca6748690a4d8f4236aa7f8a Mon Sep 17 00:00:00 2001 From: Jan Gaebel Date: Tue, 15 Jun 2021 20:06:24 +0200 Subject: [PATCH 5/6] fix(auth): ignore unknown keys --- .../kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt index 1203c9d..6e6b91b 100644 --- a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt +++ b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt @@ -37,7 +37,7 @@ class CognitoAccessToken(accessTokenString: String): JWT Date: Wed, 16 Jun 2021 11:42:05 +0200 Subject: [PATCH 6/6] refactor(auth): apply code review --- .../liftric/auth/jwt/CognitoAccessToken.kt | 7 +- .../com/liftric/auth/jwt/CognitoIdToken.kt | 5 +- .../com/liftric/auth/jwt/IdTokenSerializer.kt | 236 +++++++++--------- .../auth/AuthHandlerIntegrationTests.kt | 2 +- 4 files changed, 127 insertions(+), 123 deletions(-) diff --git a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt index 77c8119..8f9b111 100644 --- a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt +++ b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/CognitoAccessToken.kt @@ -37,9 +37,14 @@ class CognitoAccessToken(accessTokenString: String): JWT(idTokenSt try { return Json.decodeFromString(CognitoIdTokenClaims.serializer(), getPayload()) } catch (e: SerializationException) { - throw InvalidCognitoIdTokenException("This is not a valid cognito id token") + throw InvalidCognitoIdTokenException("This is not a valid cognito id token", e) } } } diff --git a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/IdTokenSerializer.kt b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/IdTokenSerializer.kt index f6bb768..0e7c52c 100644 --- a/auth/src/commonMain/kotlin/com/liftric/auth/jwt/IdTokenSerializer.kt +++ b/auth/src/commonMain/kotlin/com/liftric/auth/jwt/IdTokenSerializer.kt @@ -3,7 +3,6 @@ package com.liftric.auth.jwt import kotlinx.serialization.KSerializer import kotlinx.serialization.SerializationException import kotlinx.serialization.Serializer -import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.builtins.MapSerializer import kotlinx.serialization.builtins.serializer import kotlinx.serialization.descriptors.SerialDescriptor @@ -22,130 +21,129 @@ internal object CustomAttributesSerializer : KSerializer { val json = decoder.json val filtersMap = decoder.decodeSerializableValue(stringToJsonElementSerializer) - val address = filtersMap["address"]?.let { - json.decodeFromJsonElement(Address.serializer(), it) + val address: Address? = filtersMap["address"]?.let { + json.decodeFromJsonElement(it) } - val birthdate = filtersMap["birthdate"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val birthdate: String? = filtersMap["birthdate"]?.let { + json.decodeFromJsonElement(it) } - val email = filtersMap["email"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val email: String? = filtersMap["email"]?.let { + json.decodeFromJsonElement(it) } - val emailVerified = filtersMap["email_verified"]?.let { - json.decodeFromJsonElement(Boolean.serializer(), it) + val emailVerified: Boolean? = filtersMap["email_verified"]?.let { + json.decodeFromJsonElement(it) } - val familyName = filtersMap["family_name"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val familyName: String? = filtersMap["family_name"]?.let { + json.decodeFromJsonElement(it) } - val middleName = filtersMap["middle_name"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val middleName: String? = filtersMap["middle_name"]?.let { + json.decodeFromJsonElement(it) } - val gender = filtersMap["gender"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val gender: String? = filtersMap["gender"]?.let { + json.decodeFromJsonElement(it) } - val givenName = filtersMap["given_name"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val givenName: String? = filtersMap["given_name"]?.let { + json.decodeFromJsonElement(it) } - val locale = filtersMap["locale"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val locale: String? = filtersMap["locale"]?.let { + json.decodeFromJsonElement(it) } - val name = filtersMap["name"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val name: String? = filtersMap["name"]?.let { + json.decodeFromJsonElement(it) } - val nickname = filtersMap["nickname"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val nickname: String? = filtersMap["nickname"]?.let { + json.decodeFromJsonElement(it) } - val phoneNumber = filtersMap["phone_number"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val phoneNumber: String? = filtersMap["phone_number"]?.let { + json.decodeFromJsonElement(it) } - val phoneNumberVerified = filtersMap["phone_number_verified"]?.let { - json.decodeFromJsonElement(Boolean.serializer(), it) + val phoneNumberVerified: Boolean? = filtersMap["phone_number_verified"]?.let { + json.decodeFromJsonElement(it) } - val picture = filtersMap["picture"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val picture: String? = filtersMap["picture"]?.let { + json.decodeFromJsonElement(it) } - val profile = filtersMap["profile"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val profile: String? = filtersMap["profile"]?.let { + json.decodeFromJsonElement(it) } - val preferredUsername = filtersMap["preferred_username"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val preferredUsername: String? = filtersMap["preferred_username"]?.let { + json.decodeFromJsonElement(it) } - val sub = filtersMap["sub"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val sub: String? = filtersMap["sub"]?.let { + json.decodeFromJsonElement(it) } - val aud = filtersMap["aud"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val aud: String = filtersMap["aud"]?.let { + json.decodeFromJsonElement(it) }?: run { - throw SerializationException("Missing field aud") + throw SerializationException(missingField("aud")) } - val authTime = filtersMap["auth_time"]?.let { - json.decodeFromJsonElement(Long.serializer(), it) + val authTime: Long = filtersMap["auth_time"]?.let { + json.decodeFromJsonElement(it) }?: run { - throw SerializationException("Missing field auth_time") + throw SerializationException(missingField("auth_time")) } - val cognitoGroups = filtersMap["cognito:groups"]?.let { - json.decodeFromJsonElement(ListSerializer(String.serializer()), it) + val cognitoGroups: List = filtersMap["cognito:groups"]?.let { + json.decodeFromJsonElement(it) }?: run { - throw SerializationException("Missing field cognito:groups") + throw SerializationException(missingField("cognito:groups")) } - val cognitoUsername = filtersMap["cognito:username"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val cognitoUsername: String = filtersMap["cognito:username"]?.let { + json.decodeFromJsonElement(it) }?: run { - throw SerializationException("Missing field cognito:username") + throw SerializationException(missingField("cognito:username")) } - val exp = filtersMap["exp"]?.let { - json.decodeFromJsonElement(Long.serializer(), it) + val exp: Long = filtersMap["exp"]?.let { + json.decodeFromJsonElement(it) }?: run { - throw SerializationException("Missing field exp") + throw SerializationException(missingField("exp")) } - val eventId = filtersMap["event_id"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val eventId: String = filtersMap["event_id"]?.let { + json.decodeFromJsonElement(it) }?: run { - throw SerializationException("Missing field event_id") + throw SerializationException(missingField("event_id")) } - val jti = filtersMap["jti"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val jti: String? = filtersMap["jti"]?.let { + json.decodeFromJsonElement(it) } - val originJti = filtersMap["origin_jti"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val originJti: String? = filtersMap["origin_jti"]?.let { + json.decodeFromJsonElement(it) } - val iss = filtersMap["iss"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val iss: String = filtersMap["iss"]?.let { + json.decodeFromJsonElement(it) }?: run { - throw SerializationException("Missing field iss") + throw SerializationException(missingField("iss")) } - val zoneinfo = filtersMap["zoneinfo"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val zoneinfo: String? = filtersMap["zoneinfo"]?.let { + json.decodeFromJsonElement(it) } - val iat = filtersMap["iat"]?.let { - json.decodeFromJsonElement(Long.serializer(), it) + val iat: Long = filtersMap["iat"]?.let { + json.decodeFromJsonElement(it) }?: run { - throw SerializationException("Missing field iat") + throw SerializationException(missingField("iat")) } - val scope = filtersMap["scope"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val scope: String? = filtersMap["scope"]?.let { + json.decodeFromJsonElement(it) } - val tokenUse = filtersMap["token_use"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val tokenUse: String = filtersMap["token_use"]?.let { + json.decodeFromJsonElement(it) }?: run { - throw SerializationException("Missing field token_use") + throw SerializationException(missingField("token_use")) } - val website = filtersMap["website"]?.let { - json.decodeFromJsonElement(String.serializer(), it) + val website: String? = filtersMap["website"]?.let { + json.decodeFromJsonElement(it) } - val updatedAt = filtersMap["updated_at"]?.let { - json.decodeFromJsonElement(Long.serializer(), it) + val updatedAt: Long? = filtersMap["updated_at"]?.let { + json.decodeFromJsonElement(it) } - val unknownFilters = filtersMap.filter { (key, _) -> key.contains("custom") } - val customAttributes = mutableMapOf() - unknownFilters.forEach { - val value = if (it.value.jsonPrimitive.isString) { - json.decodeFromJsonElement(String.serializer(), it.value) + val customAttributes = filtersMap.filter { (key, _) -> + key.contains("custom") + }.map { (key, value) -> + key to if (value.jsonPrimitive.isString) { + json.decodeFromJsonElement(String.serializer(), value) } else { - json.decodeFromJsonElement(Long.serializer(), it.value).toString() + json.decodeFromJsonElement(Long.serializer(), value).toString() } - customAttributes[it.key] = value - } + }.toMap() return CognitoIdTokenClaims( sub, @@ -186,44 +184,46 @@ internal object CustomAttributesSerializer : KSerializer { override fun serialize(encoder: Encoder, value: CognitoIdTokenClaims) { require(encoder is JsonEncoder) val json = encoder.json - val map: MutableMap = mutableMapOf() - value.sub?.let { map["name"] = json.encodeToJsonElement(String.serializer(), it) } - value.name?.let { map["name"] = json.encodeToJsonElement(String.serializer(), it) } - value.givenName?.let { map["given_name"] = json.encodeToJsonElement(String.serializer(), it) } - value.familyName?.let { map["family_name"] = json.encodeToJsonElement(String.serializer(), it) } - value.middleName?.let { map["middle_name"] = json.encodeToJsonElement(String.serializer(), it) } - value.nickname?.let { map["nickname"] = json.encodeToJsonElement(String.serializer(), it) } - value.preferredUsername?.let { map["preferred_username"] = json.encodeToJsonElement(String.serializer(), it) } - value.profile?.let { map["profile"] = json.encodeToJsonElement(String.serializer(), it) } - value.picture?.let { map["picture"] = json.encodeToJsonElement(String.serializer(), it) } - value.website?.let { map["website"] = json.encodeToJsonElement(String.serializer(), it) } - value.email?.let { map["email"] = json.encodeToJsonElement(String.serializer(), it) } - value.emailVerified?.let { map["email_verified"] = json.encodeToJsonElement(Boolean.serializer(), it) } - value.gender?.let { map["gender"] = json.encodeToJsonElement(String.serializer(), it) } - value.birthdate?.let { map["birthdate"] = json.encodeToJsonElement(String.serializer(), it) } - value.zoneinfo?.let { map["zoneinfo"] = json.encodeToJsonElement(String.serializer(), it) } - value.locale?.let { map["locale"] = json.encodeToJsonElement(String.serializer(), it) } - value.phoneNumber?.let { map["phone_number"] = json.encodeToJsonElement(String.serializer(), it) } - value.phoneNumberVerified?.let { map["phone_number_verified"] = json.encodeToJsonElement(Boolean.serializer(), it) } - value.address?.let { map["address"] = json.encodeToJsonElement(Address.serializer(), it) } - value.updatedAt?.let { map["updated_at"] = json.encodeToJsonElement(Long.serializer(), it) } - value.aud.let { map["aud"] = json.encodeToJsonElement(String.serializer(), it) } - value.authTime.let { map["auth_time"] = json.encodeToJsonElement(Long.serializer(), it) } - value.cognitoGroups.let { map["cognito:groups"] = json.encodeToJsonElement(ListSerializer(String.serializer()), it) } - value.cognitoUsername.let { map["cognito:username"] = json.encodeToJsonElement(String.serializer(), it) } - value.exp.let { map["exp"] = json.encodeToJsonElement(Long.serializer(), it) } - value.eventId.let { map["event_id"] = json.encodeToJsonElement(String.serializer(), it) } - value.jti?.let { map["jti"] = json.encodeToJsonElement(String.serializer(), it) } - value.originJti?.let { map["origin_jti"] = json.encodeToJsonElement(String.serializer(), it) } - value.iss.let { map["iss"] = json.encodeToJsonElement(String.serializer(), it) } - value.iat.let { map["iat"] = json.encodeToJsonElement(Long.serializer(), it) } - value.scope?.let { map["scope"] = json.encodeToJsonElement(String.serializer(), it) } - value.tokenUse.let { map["token_user"] = json.encodeToJsonElement(String.serializer(), it) } - value.customAttributes?.forEach { - map[it.key] = json.encodeToJsonElement(String.serializer(), it.value) - } + val map: MutableMap = mutableMapOf() + value.sub?.let { map["name"] = json.encodeToJsonElement(it) } + value.name?.let { map["name"] = json.encodeToJsonElement(it) } + value.givenName?.let { map["given_name"] = json.encodeToJsonElement(it) } + value.familyName?.let { map["family_name"] = json.encodeToJsonElement(it) } + value.middleName?.let { map["middle_name"] = json.encodeToJsonElement(it) } + value.nickname?.let { map["nickname"] = json.encodeToJsonElement(it) } + value.preferredUsername?.let { map["preferred_username"] = json.encodeToJsonElement(it) } + value.profile?.let { map["profile"] = json.encodeToJsonElement(it) } + value.picture?.let { map["picture"] = json.encodeToJsonElement(it) } + value.website?.let { map["website"] = json.encodeToJsonElement(it) } + value.email?.let { map["email"] = json.encodeToJsonElement(it) } + value.emailVerified?.let { map["email_verified"] = json.encodeToJsonElement(it) } + value.gender?.let { map["gender"] = json.encodeToJsonElement(it) } + value.birthdate?.let { map["birthdate"] = json.encodeToJsonElement(it) } + value.zoneinfo?.let { map["zoneinfo"] = json.encodeToJsonElement(it) } + value.locale?.let { map["locale"] = json.encodeToJsonElement(it) } + value.phoneNumber?.let { map["phone_number"] = json.encodeToJsonElement(it) } + value.phoneNumberVerified?.let { map["phone_number_verified"] = json.encodeToJsonElement(it) } + value.address?.let { map["address"] = json.encodeToJsonElement(it) } + value.updatedAt?.let { map["updated_at"] = json.encodeToJsonElement(it) } + value.aud.let { map["aud"] = json.encodeToJsonElement(it) } + value.authTime.let { map["auth_time"] = json.encodeToJsonElement(it) } + value.cognitoGroups.let { map["cognito:groups"] = json.encodeToJsonElement(it) } + value.cognitoUsername.let { map["cognito:username"] = json.encodeToJsonElement(it) } + value.exp.let { map["exp"] = json.encodeToJsonElement(it) } + value.eventId.let { map["event_id"] = json.encodeToJsonElement(it) } + value.jti?.let { map["jti"] = json.encodeToJsonElement(it) } + value.originJti?.let { map["origin_jti"] = json.encodeToJsonElement(it) } + value.iss.let { map["iss"] = json.encodeToJsonElement(it) } + value.iat.let { map["iat"] = json.encodeToJsonElement(it) } + value.scope?.let { map["scope"] = json.encodeToJsonElement(it) } + value.tokenUse.let { map["token_user"] = json.encodeToJsonElement(it) } + value.customAttributes?.forEach { map[it.key] = json.encodeToJsonElement(it.value) } encoder.encodeSerializableValue(stringToJsonElementSerializer, map) } + + private fun missingField(name: String): String { + return "Missing field $name" + } } \ No newline at end of file diff --git a/auth/src/commonTest/kotlin/com/liftric/auth/AuthHandlerIntegrationTests.kt b/auth/src/commonTest/kotlin/com/liftric/auth/AuthHandlerIntegrationTests.kt index 73c4b7b..69f71e7 100644 --- a/auth/src/commonTest/kotlin/com/liftric/auth/AuthHandlerIntegrationTests.kt +++ b/auth/src/commonTest/kotlin/com/liftric/auth/AuthHandlerIntegrationTests.kt @@ -238,7 +238,7 @@ abstract class AbstractAuthHandlerIntegrationTests() { @JsName("SignUpFailUsernameTooLongTest") @Test fun `Sign up should fail because username too long`() = runTest { - var signUpResponse = authHandler.signUp( + val signUpResponse = authHandler.signUp( buildString { (1..130).forEach { _ -> append("A") } }, "Password", attributes = listOf( UserAttribute(Name = "custom:target_group", Value = "ROLE_USER")