Closed Sawdre closed 2 months ago
Hi @Sawdre ,
Before you start coding with aws-sdk-ios, have you checked using the AWS CLI to ensure that the magicLinkToken
you received via email is actually functional?
hello @5d thank you for your response, yes I have this functionality working on android and token is valid there.
To help us debug further, would you be able to provide verbose logs when the error occurs. You can enable verbose logging to the console by doing this:
AWSDDLog.sharedInstance.logLevel = .verbose AWSDDLog.add(AWSDDTTYLogger.sharedInstance)
Furthermore, have you tried using AWS Amplify, which is has a lot a good Auth API's that make writing and handling logic very easy.
Okay, I found what the issue was. Actually, there were three issues:
challengeResponseRequest.challengeResponses = @{ @"USERNAME": username, @"ANSWER": magicLinkToken // token parsed from the email };
Thank you @harsh62 and @5d for responding
See last comment
@Sawdre Did you try the same thing using AWS Amplify?
@harsh62 well it was my first intent indeed, but I did not find in the documentation that Amplify supports it.
@Sawdre
Here is how you can use the sign in API's:
import Amplify
import AWSCognitoAuthPlugin
func magicLinkSignIn() async throws {
let result = try await Amplify.Auth.signIn(username: "<username>", options: .init(pluginOptions: AWSAuthSignInOptions(authFlowType: .customWithoutSRP)))
switch result.nextStep {
case .confirmSignInWithCustomChallenge(let info):
let signedInResult = try await Amplify.Auth.confirmSignIn(challengeResponse: "<your magic link response>")
default:
break
}
}
If you want to manually configure, you can use:
func configureAmplify() {
do {
try Amplify.add(plugin: AWSCognitoAuthPlugin())
let configuration = AmplifyConfiguration(
auth: AuthCategoryConfiguration(
plugins: [
"awsCognitoAuthPlugin": [
"IdentityManager": [
"Default": [:]
],
"CognitoUserPool": [
"Default": [
"PoolId": "<userPoolId>",
"Region": "<region>",
"AppClientId": "<appClientId>"
]
]
]
]
)
)
try Amplify.configure(configuration)
Amplify.Logging.logLevel = .verbose
} catch {
print("Failed to initialize Amplify with \(error)")
}
}
Here is an example how you can also setup your lambdas. https://docs.amplify.aws/swift/build-a-backend/functions/examples/google-recaptcha-challenge/
The example shows google recaptcha challenge, but you can tweak the implementation to your own liking and pretty much do anything.
Aha! Thanks @harsh62 I will try
Good afternoon! I need your help.
I need to implement AWS Cognito Magic Link to authenticate the user. I made in-app request to send an email. I do receive email with token. I parse it in the app. How to proceed with it and pass this token to sdk to authenticate the user.
In response from SDK I am getting an error:
Not sure why password is there in MagicLink implementation, but username is correct.
I am doing the following: self.magicLinkToken // token parsed from the email
I hope for your help as I don't have any ideas anymore. Thank you in advance!