Skip to content

Commit

Permalink
Merge pull request #58 from Liftric/fix/js-object-diverged
Browse files Browse the repository at this point in the history
Fix: JS and common response objects diverged
  • Loading branch information
benjohnde authored Aug 17, 2022
2 parents dded317 + 5f1fc61 commit 485f342
Show file tree
Hide file tree
Showing 10 changed files with 236 additions and 176 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ out
.directory
node_modules
local.properties
kotlin-js-store/

.DS_Store
.externalNativeBuild
Expand All @@ -38,4 +39,4 @@ DerivedData/
.build/
!*.xcodeproj/xcshareddata/
!*.xcworkspace/contents.xcworkspacedata
**/xcshareddata/WorkspaceSettings.xcsettings
**/xcshareddata/WorkspaceSettings.xcsettings
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ open class IdentityProviderClient(region: String, clientId: String) : IdentityPr
private val json = Json {
allowStructuredMapKeys = true
ignoreUnknownKeys = true
explicitNulls = false
}
private val configuration = Configuration(region, clientId)
private val client = HttpClient {
Expand Down Expand Up @@ -209,26 +210,48 @@ open class IdentityProviderClient(region: String, clientId: String) : IdentityPr
)

override suspend fun associateSoftwareToken(
accessToken: String?,
session: String?
accessToken: String
): Result<AssociateSoftwareTokenResponse> = request(
Request.AssociateSoftwareToken,
AssociateSoftwareToken(
AccessToken = accessToken,
Session = null
)
)

override suspend fun associateSoftwareTokenBySession(
session: String
): Result<AssociateSoftwareTokenResponse> = request(
Request.AssociateSoftwareToken,
AssociateSoftwareToken(
AccessToken = null,
Session = session
)
)

override suspend fun verifySoftwareToken(
accessToken: String?,
accessToken: String,
friendlyDeviceName: String?,
session: String?,
userCode: String
): Result<VerifySoftwareTokenResponse> = request(
Request.VerifySoftwareToken,
VerifySoftwareToken(
AccessToken = accessToken,
FriendlyDeviceName = friendlyDeviceName,
Session = null,
UserCode = userCode
)
)

override suspend fun verifySoftwareTokenBySession(
session: String,
friendlyDeviceName: String?,
userCode: String
): Result<VerifySoftwareTokenResponse> = request(
Request.VerifySoftwareToken,
VerifySoftwareToken(
AccessToken = null,
FriendlyDeviceName = friendlyDeviceName,
Session = session,
UserCode = userCode
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,26 +149,45 @@ interface IdentityProvider {
/**
* Associate a TOTP device with the user account
* @param accessToken The access token from the sign in request
* @param session The session that should be passed both ways in challenge-response calls to the service. This allows authentication of the user as part of the MFA setup process.
* @return Result object containing AssociateSoftwareTokenResponse object on success or an error on failure
*/
suspend fun associateSoftwareToken(
accessToken: String?,
session: String?
accessToken: String
): Result<AssociateSoftwareTokenResponse>

/**
* Associate a TOTP device with the user account
* @param session The session that should be passed both ways in challenge-response calls to the service. This allows authentication of the user as part of the MFA setup process.
* @return Result object containing AssociateSoftwareTokenResponse object on success or an error on failure
*/
suspend fun associateSoftwareTokenBySession(
session: String
): Result<AssociateSoftwareTokenResponse>

/**
* Verifies TOTP code and mark the user's software token MFA status as "verified"
* @param accessToken The access token from the sign in request
* @param friendlyDeviceName Name of the device the token was generated on
* @param session The session that should be passed both ways in challenge-response calls to the service. This allows authentication of the user as part of the MFA setup process.
* @param userCode One-time password computed using the secret code returned by associateSoftwareToken
* @return Result object containing VerifySoftwareTokenResponse object on success or an error on failure
*/
suspend fun verifySoftwareToken(
accessToken: String?,
accessToken: String,
friendlyDeviceName: String?,
session: String?,
userCode: String
): Result<VerifySoftwareTokenResponse>

/**
* Verifies TOTP code and mark the user's software token MFA status as "verified"
* @param friendlyDeviceName Name of the device the token was generated on
* @param session The session that should be passed both ways in challenge-response calls to the service. This allows authentication of the user as part of the MFA setup process.
* @param userCode One-time password computed using the secret code returned by associateSoftwareToken
* @return Result object containing VerifySoftwareTokenResponse object on success or an error on failure
*/
suspend fun verifySoftwareTokenBySession(
session: String,
friendlyDeviceName: String?,
userCode: String
): Result<VerifySoftwareTokenResponse>

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ internal data class ConfirmForgotPassword(
val Password: String
)

@JsExport
@Serializable
data class UserAttribute(
val Name: String,
Expand Down Expand Up @@ -144,4 +145,4 @@ data class RespondToAuthChallenge(
val ChallengeResponses: Map<String, String> = mapOf(),
val ClientId: String,
val Session: String?,
)
)
52 changes: 30 additions & 22 deletions src/commonMain/kotlin/com/liftric/cognito/idp/core/Response.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,72 +16,80 @@ data class RequestError(

@Serializable
data class SignInResponse(
val AuthenticationResult: AuthenticationResult? = null,
val AuthenticationResult: AuthenticationResult?,
val ChallengeParameters: Map<String, String> = mapOf(),
val ChallengeName: String? = null,
val Session: String = ""
val ChallengeName: String?,
val Session: String?
)

@JsExport
@Serializable
data class AuthenticationResult(
val AccessToken: String,
val ExpiresIn: Int,
val IdToken: String,
val RefreshToken: String? = null,
val TokenType: String,
val NewDeviceMetadata: NewDeviceMetadata? = null,
val AccessToken: String?,
val ExpiresIn: Int?,
val IdToken: String?,
val RefreshToken: String?,
val TokenType: String?,
val NewDeviceMetadata: NewDeviceMetadata?,
)

@JsExport
@Serializable
data class NewDeviceMetadata(
val DeviceGroupKey: String? = null,
val DeviceKey: String? = null,
val DeviceGroupKey: String?,
val DeviceKey: String?,
)

@JsExport
@Serializable
data class SignUpResponse(
val CodeDeliveryDetails: CodeDeliveryDetails? = null,
val UserConfirmed: Boolean = false,
val CodeDeliveryDetails: CodeDeliveryDetails?,
val UserConfirmed: Boolean,
val UserSub: String
)

@JsExport
@Serializable
data class ResendConfirmationCodeResponse(
val CodeDeliveryDetails: CodeDeliveryDetails
)

@JsExport
@Serializable
data class CodeDeliveryDetails(
val AttributeName: String,
val DeliveryMedium: String,
val Destination: String
val AttributeName: String?,
val DeliveryMedium: String?,
val Destination: String?
)

@Serializable
data class GetUserResponse(
val MFAOptions: MFAOptions? = null,
val PreferredMfaSetting: String? = null,
val MFAOptions: MFAOptions?,
val PreferredMfaSetting: String?,
val UserAttributes: List<UserAttribute> = listOf(),
val UserMFASettingList: List<String> = listOf(),
val Username: String
)

@JsExport
@Serializable
data class MFAOptions(
val AttributeName: String,
val DeliveryMedium: String
val AttributeName: String?,
val DeliveryMedium: String?
)

@Serializable
data class UpdateUserAttributesResponse(
val CodeDeliveryDetailsList: List<CodeDeliveryDetails> = listOf()
)

@JsExport
@Serializable
data class GetAttributeVerificationCodeResponse(
val CodeDeliveryDetails: CodeDeliveryDetails
)

@JsExport
@Serializable
data class ForgotPasswordResponse(
val CodeDeliveryDetails: CodeDeliveryDetails
Expand All @@ -91,12 +99,12 @@ data class ForgotPasswordResponse(
@Serializable
data class AssociateSoftwareTokenResponse(
val SecretCode: String,
val Session: String? = null
val Session: String?
)

@JsExport
@Serializable
data class VerifySoftwareTokenResponse(
val Session: String? = null,
val Session: String?,
val Status: String
)
Loading

0 comments on commit 485f342

Please sign in to comment.