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

fix(amplify_auth_cognito): fixes auth null safety issues #613

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -32,13 +32,24 @@ data class FlutterFetchCognitoAuthSessionResult(private val raw: AWSCognitoAuthS
private val tokens: AuthSessionResult<AWSCognitoUserPoolTokens>? = raw.userPoolTokens

fun toValueMap(): Map<String, Any?> {
return mapOf(
var serializedMap = mutableMapOf(
"isSignedIn" to this.isSignedIn,
"identityId" to this.identityId,
"userSub" to this.userSub,
"credentials" to serializeCredentials(this.credentials),
"tokens" to serializeTokens(this.tokens)
"userSub" to this.userSub
)

var credentials = serializeCredentials(this.credentials)
var tokens = serializeTokens(this.tokens)

if (credentials != null) {
serializedMap["credentials"] = credentials
}

if (tokens != null) {
serializedMap["tokens"] = tokens
}

return serializedMap;
}

//parse userpool tokens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,11 @@ import com.google.gson.Gson

data class FlutterUpdateUserAttributeResult(private val raw: AuthUpdateAttributeResult) {
val isUpdated: Boolean = raw.isUpdated
val nextStep: Map<String, Any> = setNextStep();

private fun setNextStep(): Map<String, Any> {
return mapOf(
"updateAttributeStep" to raw.nextStep.updateAttributeStep.toString(),
"additionalInfo" to Gson().toJson(raw.nextStep.additionalInfo),
"codeDeliveryDetails" to mapOf(
"destination" to (raw.nextStep.codeDeliveryDetails?.destination ?: ""),
"deliveryMedium" to (raw.nextStep.codeDeliveryDetails?.deliveryMedium?.name ?: ""),
"attributeName" to (raw.nextStep.codeDeliveryDetails?.attributeName ?: "")
)
)
}
val nextStep: Map<String, Any> = com.amazonaws.amplify.amplify_auth_cognito.setNextStep(
haverchuck marked this conversation as resolved.
Show resolved Hide resolved
"updateAttributeStep",
raw.nextStep.updateAttributeStep.toString(),
raw.nextStep.codeDeliveryDetails,
raw.nextStep.additionalInfo)

fun toValueMap(): Map<String, Any> {
return mapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,6 @@ class AmplifyAuthCognitoPluginTest {
"isUpdated" to true,
"nextStep" to mapOf(
"updateAttributeStep" to "CONFIRM_ATTRIBUTE_WITH_CODE",
"additionalInfo" to "{}",
"codeDeliveryDetails" to mapOf(
"destination" to "[email protected]",
"deliveryMedium" to AuthCodeDeliveryDetails.DeliveryMedium.EMAIL.name,
Expand Down Expand Up @@ -553,7 +552,6 @@ class AmplifyAuthCognitoPluginTest {
"isUpdated" to true,
"nextStep" to mapOf(
"updateAttributeStep" to "CONFIRM_ATTRIBUTE_WITH_CODE",
"additionalInfo" to "{}",
"codeDeliveryDetails" to mapOf(
"destination" to "[email protected]",
"deliveryMedium" to AuthCodeDeliveryDetails.DeliveryMedium.EMAIL.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,7 @@ class amplify_auth_cognito_tests: XCTestCase {
XCTAssertEqual(false, res.toJSON()["isSignedIn"] as? Bool)
XCTAssertEqual("testid", res.toJSON()["identityId"] as? String)
// userSub error will result in map with one 'error' key
XCTAssertEqual(1, (res.toJSON()["tokens"] as? [String: String])!.count)
XCTAssertEqual(nil, (res.toJSON()["tokens"] as? [String: String]))
haverchuck marked this conversation as resolved.
Show resolved Hide resolved
// credentials map should have access key and secret key
XCTAssertEqual(2, (res.toJSON()["credentials"] as? [String: String])!.count)
} else {
Expand Down Expand Up @@ -1389,7 +1389,7 @@ class amplify_auth_cognito_tests: XCTestCase {
// all tokens should be present with userpool-only access
XCTAssertEqual(3, (res.toJSON()["tokens"] as? [String: String])!.count)
// credentials map should be empty
XCTAssertEqual(0, (res.toJSON()["credentials"] as? [String: String])!.count)
XCTAssertEqual(nil, (res.toJSON()["credentials"] as? [String: String]))
haverchuck marked this conversation as resolved.
Show resolved Hide resolved
} else {
XCTFail()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ struct FlutterFetchCognitoSessionResult {
func toJSON() -> Dictionary<String, Any> {
var result: Dictionary<String, Any> = [:]
result["isSignedIn"] = self.isSignedIn
result["credentials"] = self.credentials
result["identityId"] = self.identityId
if (!self.credentials.isEmpty) {
result["credentials"] = self.credentials
}
if (!self.userPoolTokens.isEmpty) {
result["tokens"] = self.userPoolTokens
}
Expand Down Expand Up @@ -131,9 +133,7 @@ func getCredentials(session: AuthSession) throws -> [String: String] {
tokenMap["accessToken"] = tokens.accessToken
tokenMap["idToken"] = tokens.idToken
tokenMap["refreshToken"] = tokens.refreshToken
} catch {
tokenMap["error"] = "You are currently signed out."
}
} catch {}
}
return tokenMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,22 @@ struct FlutterUpdateUserAttributeResult {
self.additionalInfo = setAdditionalInfo(res: res)
self.codeDeliveryDetails = setCodeDeliveryDetails(res: res)
}

haverchuck marked this conversation as resolved.
Show resolved Hide resolved
func toJSON() -> Dictionary<String, Any> {
return [
"isUpdated": self.isUpdated,
"nextStep": [
"updateAttributeStep": self.updateAttributeStep,
"additionalInfo": self.additionalInfo,
"codeDeliveryDetails": self.codeDeliveryDetails
]
]
var result: Dictionary<String, Any> = ["isUpdated": self.isUpdated]
var nextStep: Dictionary<String, Any> = ["updateAttributeStep": self.updateAttributeStep]

if (!self.codeDeliveryDetails.isEmpty) {
nextStep["codeDeliveryDetails"] = self.codeDeliveryDetails
}

if (!self.additionalInfo.isEmpty) {
nextStep["additionalInfo"] = self.additionalInfo
}

result["nextStep"] = nextStep

return result
}
}

Expand Down