I'm somewhat new to Swift but I'm trying to adapt the AWSCognitoAuth to a Swift plugin for Capacitor. I've created a repo here: https://github.com/Kikketer/CapacitorTest
One of the biggest issues is that the callback is not being fired inside the iOS project:
cognitoAuth.getSession(self.bridge.viewController) { (session, err) in
// this is never called after I click the "sign in" button in Cognito
if(err != nil) {
NSLog(err.debugDescription)
call.reject(err.debugDescription)
} else {
call.resolve([
"accessToken": session?.accessToken?.tokenString ?? ""])
}
}
Through all the setup I have described in the readme, this is the hightlight:
I'm not seeing any obvious errors in any of the logs, so I'm not sure where to go next with this.
I realize there's quite a bit of setup to repeat this issue, but any help would be appreciated.
EDIT: I've done a little closer investigation and I'm getting a 405
response but no actual error message is displaying on the page:
The Server responded with a status of 405
https://[mydomain].auth.us-east-2.amazoncognito.com/login?response_type=code&client_id=[myclientid]&state=[a big guid]&redirect_uri=com.testthing.myapp://signin&scope=email%20openid&code_challenge=[a long code]&code_challenge_method=S256
So I figured it out after I was thinking about that 405 (method not allowed) error. What was happening is the POST was being sent to my application but my application wasn't handling a POST (because Capacitor handles GETs by default).
It was a simple change to get this to work fully, updated the AppDelegate.swift
file to handle the open url
properly:
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
// TODO parse the url and only launch cognito auth for ://signin and ://signout
return AWSCognitoAuth(forKey: "AWSCognito").application(app, open: url, options: options)
// This was here before
//return CAPBridge.handleOpenUrl(url, options)
}
Hope this helps anyone else trying their hand at Cognito + Swift.