Calling Auth.SignInWithWebUI results in nothing happening
januaryblues opened this issue · 6 comments
Describe the bug
I have created a minimal swift app to test federated log in with Amplify. I have created a button that calls the Amplify.Auth.signInWithWebUI method. When I click the button, the method is successfully called, but no Web UI appears on the screen and no error is thrown - there appears to be no side affect to calling the method at all
Steps To Reproduce
Steps to reproduce the behavior:
1. Configure Amplify
2. Click login button
3. Observe... nothing
Minimal example:
Main app:
import Amplify
import SwiftUI
import AWSCognitoAuthPlugin
@main
struct SwiftOauthMinimalApp: App {
init() {
do {
try Amplify.add(plugin: AWSCognitoAuthPlugin())
try Amplify.configure()
print("Successfully configured Amplify")
} catch {
print("Unable to configure Amplify")
print("Error: \(error)")
}
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
ContentView:
import Amplify
import Combine
import SwiftUI
struct ContentView: View {
var body: some View {
Button("Log in") {
if let windowScene = UIApplication.shared.connectedScenes.first
as? UIWindowScene,
let window = windowScene.windows.first
{
print("\(window)")
Task { await signInWithWebUI(window: window) }
} else {
print("Failed to access main window.")
}
}
}
}
func signInWithWebUI(window: UIWindow) async {
do {
let signInResult = try await Amplify.Auth.signInWithWebUI(for: .custom("Auth0"),
presentationAnchor: window)
if signInResult.isSignedIn {
print("Sign in succeeded")
}
} catch let error as AuthError {
print("Sign in failed \(error)")
} catch {
print("Unexpected error: \(error)")
}
}
amplifyconfiguration.json:
{
"auth": {
"plugins": {
"awsCognitoAuthPlugin": {
"IdentityManager": {
"Default": {}
},
"CognitoUserPool": {
"Default": {
"PoolId": "XXXX",
"AppClientId": "XXXX",
"Region": "eu-west-2"
}
},
"Auth": {
"Default": {
"authenticationFlowType": "USER_SRP_AUTH",
"OAuth": {
"WebDomain": "XXXX",
"AppClientId": "XXXX",
"SignInRedirectURI": "XXXX://",
"SignOutRedirectURI": "XXXX://",
"Scopes": [
"email",
"openid",
"profile",
],
"responseType": "code",
}
}
}
}
}
}
}
Expected behavior
WebUI to appear on screen
Amplify Framework Version
2.42.1
Amplify Categories
Auth
Dependency manager
Swift PM
Swift version
6.0
CLI version
None
Xcode version
16.0
Relevant log output
<details>
<summary>Log Messages</summary>
Successfully configured Amplify
<UIWindow: 0x103508220; frame = (0 0; 393 852); gestureRecognizers = <NSArray: 0x600000c7cc90>; layer = <UIWindowLayer: 0x600000c7c060>>
Is this a regression?
No
Regression additional context
No response
Platforms
iOS
OS Version
iOS 18.0
Device
iPhone 14 Pro Max
Specific to simulators
No response
Additional context
No response
Hi @januaryblues, thanks for opening this issue. We will attempt to reproduce it and post any updates in here.
In the meantime, could you please share the verbose logs when you call signInWithWebUI
? They might help us diagnose your issue.
You can enable verbose logging by doing this before Amplify.configure()
:
Amplify.Logging.logLevel = .verbose
Thanks @ruisebas for the speedy response. Here is the verbose logs (with some sensitive stuff redacted from the URL in the final log message):
Configuring
Configuration: nil
Could not find Cognito Identity Pool configuration
Credential Store state change:
{
"CredentialStoreState.notConfigured" = {
};
}
Auth state change:
{
"AuthState.notConfigured" = {
};
}
Successfully configured Amplify
Auth state change:
{
"AuthState.configuringAuth" = {
};
}
AWSCognitoAuthPlugin/InitializeAuthConfiguration.swift Starting execution
Credential Store state change:
{
"CredentialStoreState.migratingLegacyStore" = {
};
}
AWSCognitoAuthPlugin/MigrateLegacyCredentialStore.swift Starting execution
[KeychainStore] Initialized keychain with service=com.amplify.awsCognitoAuthPlugin, attributes=KeychainStoreAttributes(itemClass: "genp", service: "com.amplify.awsCognitoAuthPlugin", accessGroup: nil), accessGroup=
[KeychainStore] Started retrieving `Data` from the store with key=authConfiguration
[KeychainStore] Successfully retrieved `Data` from the store with key=authConfiguration
[KeychainStore] Started setting `Data` for key=authConfiguration
[KeychainStore] Initialized fetching to decide whether update or add
[KeychainStore] Found existing item, updating
[KeychainStore] Successfully updated `Data` in keychain for key=authConfiguration
[KeychainStore] Initialized keychain with service=com.example.SwiftOauthMinimal.AWSCognitoIdentityUserPool, attributes=KeychainStoreAttributes(itemClass: "genp", service: "com.example.SwiftOauthMinimal.AWSCognitoIdentityUserPool", accessGroup: nil), accessGroup=
[KeychainStore] Started retrieving `String` from the store with key=2hq63pmn2836qoas360c21cid6.currentUser
[KeychainStore] Started retrieving `Data` from the store with key=2hq63pmn2836qoas360c21cid6.currentUser
[KeychainStore] No Keychain item found for key=2hq63pmn2836qoas360c21cid6.currentUser
[KeychainStore] Initialized keychain with service=com.example.SwiftOauthMinimal.AWSCognitoIdentityUserPool, attributes=KeychainStoreAttributes(itemClass: "genp", service: "com.example.SwiftOauthMinimal.AWSCognitoIdentityUserPool", accessGroup: nil), accessGroup=
[KeychainStore] Started retrieving `String` from the store with key=2hq63pmn2836qoas360c21cid6.currentUser
[KeychainStore] Started retrieving `Data` from the store with key=2hq63pmn2836qoas360c21cid6.currentUser
[KeychainStore] No Keychain item found for key=2hq63pmn2836qoas360c21cid6.currentUser
[KeychainStore] Starting to remove all items from keychain
[KeychainStore] Successfully removed all items from keychain
[KeychainStore] Initialized keychain with service=Optional("com.example.SwiftOauthMinimal").AWSMobileClient, attributes=KeychainStoreAttributes(itemClass: "genp", service: "Optional(\"com.example.SwiftOauthMinimal\").AWSMobileClient", accessGroup: nil), accessGroup=
[KeychainStore] Started retrieving `Data` from the store with key=loginsMap
[KeychainStore] No Keychain item found for key=loginsMap
[KeychainStore] Initialized keychain with service=Optional("com.example.SwiftOauthMinimal").AWSMobileClient, attributes=KeychainStoreAttributes(itemClass: "genp", service: "Optional(\"com.example.SwiftOauthMinimal\").AWSMobileClient", accessGroup: nil), accessGroup=
[KeychainStore] Started retrieving `String` from the store with key=federationProvider
[KeychainStore] Started retrieving `Data` from the store with key=federationProvider
[KeychainStore] No Keychain item found for key=federationProvider
[KeychainStore] Starting to remove all items from keychain
[KeychainStore] Successfully removed all items from keychain
AWSCognitoAuthPlugin/MigrateLegacyCredentialStore.swift Sending event CredentialStoreEvent.loadCredentialStore
Credential Store state change:
{
"CredentialStoreState.loadingStoredCredentials" = {
};
}
AWSCognitoAuthPlugin/LoadCredentialStore.swift Starting execution
AWSCognitoAuthPlugin/LoadCredentialStore.swift Retreiving credential amplifyCredentials
[KeychainStore] Initialized keychain with service=com.amplify.awsCognitoAuthPlugin, attributes=KeychainStoreAttributes(itemClass: "genp", service: "com.amplify.awsCognitoAuthPlugin", accessGroup: nil), accessGroup=
[KeychainStore] Started retrieving `Data` from the store with key=authConfiguration
[KeychainStore] Successfully retrieved `Data` from the store with key=authConfiguration
[KeychainStore] Started setting `Data` for key=authConfiguration
[KeychainStore] Initialized fetching to decide whether update or add
[KeychainStore] Found existing item, updating
[KeychainStore] Successfully updated `Data` in keychain for key=authConfiguration
[KeychainStore] Started retrieving `Data` from the store with key=amplify.eu-west-2_mQiFbuxB0.session
[KeychainStore] No Keychain item found for key=amplify.eu-west-2_mQiFbuxB0.session
AWSCognitoAuthPlugin/LoadCredentialStore.swift Sending event CredentialStoreEvent.throwError
AWSCognitoAuthPlugin/IdleCredentialStore.swift Starting execution
AWSCognitoAuthPlugin/IdleCredentialStore.swift Sending event CredentialStoreEvent.moveToIdleState
No existing session found.
AWSCognitoAuthPlugin/InitializeAuthConfiguration.swift Sending event AuthEvent.validateCredentialAndConfiguration
AWSCognitoAuthPlugin/ValidateCredentialsAndConfiguration.swift Starting execution
AWSCognitoAuthPlugin/ValidateCredentialsAndConfiguration.swift Sending event AuthEvent.configureAuthentication
Auth state change:
{
"AuthState.validatingCredentialsAndConfiguration" = {
};
}
AWSCognitoAuthPlugin/InitializeAuthenticationConfiguration.swift Starting execution
Auth state change:
{
"AuthState.configuringAuthentication" = {
"AuthenticationState.notConfigured" = {
};
};
}
AWSCognitoAuthPlugin/InitializeAuthenticationConfiguration.swift Sending event AuthenticationEvent.configure
Credential Store state change:
{
"CredentialStoreState.error" = {
errorType = "KeychainStoreError: Unable to find the keychain item";
};
}
Credential Store state change:
{
"CredentialStoreState.idle" = {
};
}
Auth state change:
{
"AuthState.configuringAuthentication" = {
"AuthenticationState.configured" = {
};
};
}
AWSCognitoAuthPlugin/ConfigureAuthentication.swift Start execution
AWSCognitoAuthPlugin/ConfigureAuthentication.swift Sending event AuthenticationEvent.initializedSignedOut
AWSCognitoAuthPlugin/ConfigureAuthentication.swift Sending event AuthEvent.authenticationConfigured
Auth state change:
{
"AuthState.configuringAuthentication" = {
"AuthenticationState.signedOut" = {
lastKnownUserName = "(nil)";
};
};
}
AWSCognitoAuthPlugin/InitializeAuthorizationConfiguration.swift Starting execution
Auth state change:
{
"AuthState.configuringAuthorization" = {
"AuthenticationState.signedOut" = {
lastKnownUserName = "(nil)";
};
"AuthorizationState.notConfigured" = {
};
};
}
AWSCognitoAuthPlugin/InitializeAuthorizationConfiguration.swift Sending event AuthorizationEvent.configure
AWSCognitoAuthPlugin/ConfigureAuthorization.swift Starting execution
AWSCognitoAuthPlugin/ConfigureAuthorization.swift Sending event AuthEvent.authorizationConfigured
Auth state change:
{
"AuthState.configuringAuthorization" = {
"AuthenticationState.signedOut" = {
lastKnownUserName = "(nil)";
};
"AuthorizationState.configured" = {
};
};
}
Auth state change:
{
"AuthState.configured" = {
"AuthenticationState.signedOut" = {
lastKnownUserName = "(nil)";
};
"AuthorizationState.configured" = {
};
};
}
<UIWindow: 0x103e0ba70; frame = (0 0; 393 852); gestureRecognizers = <NSArray: 0x600000c7c030>; layer = <UIWindowLayer: 0x600000c56eb0>>
Starting execution for Auth.socialWebUISignInAPI
Check if authstate configured
Auth state configured
Wait for a valid state
Start signIn flow
Wait for signIn to complete
Auth state change:
{
"AuthState.configured" = {
"AuthenticationState.signingIn" = {
"SignInState.notStarted" = {
};
};
"AuthorizationState.configured" = {
};
};
}
AWSCognitoAuthPlugin/IntializeSignInFlow.swift Starting execution
AWSCognitoAuthPlugin/IntializeSignInFlow.swift Sending event SignInEvent.initiateHostedUISignIn
Checking next step for: notStarted
AWSCognitoAuthPlugin/InitializeHostedUISignIn.swift Starting execution
Auth state change:
{
"AuthState.configured" = {
"AuthenticationState.signingIn" = {
"SignInState.signingInWithHostedUI" = {
"HostedUISignInState.notStarted" = {
};
};
};
"AuthorizationState.configured" = {
};
};
}
AWSCognitoAuthPlugin/LoadCredentialStore.swift Starting execution
Credential Store state change:
{
"CredentialStoreState.loadingStoredCredentials" = {
};
}
Checking next step for: signingInWithHostedUI(AWSCognitoAuthPlugin.HostedUISignInState.notStarted)
AWSCognitoAuthPlugin/LoadCredentialStore.swift Retreiving credential deviceMetadata(username: "unknown")
[KeychainStore] Initialized keychain with service=com.amplify.awsCognitoAuthPlugin, attributes=KeychainStoreAttributes(itemClass: "genp", service: "com.amplify.awsCognitoAuthPlugin", accessGroup: nil), accessGroup=
[KeychainStore] Started retrieving `Data` from the store with key=authConfiguration
[KeychainStore] Successfully retrieved `Data` from the store with key=authConfiguration
[KeychainStore] Started setting `Data` for key=authConfiguration
[KeychainStore] Initialized fetching to decide whether update or add
[KeychainStore] Found existing item, updating
[KeychainStore] Successfully updated `Data` in keychain for key=authConfiguration
[KeychainStore] Started retrieving `Data` from the store with key=amplify.eu-west-2_mQiFbuxB0.unknown.deviceMetadata
[KeychainStore] No Keychain item found for key=amplify.eu-west-2_mQiFbuxB0.unknown.deviceMetadata
AWSCognitoAuthPlugin/LoadCredentialStore.swift Sending event CredentialStoreEvent.throwError
AWSCognitoAuthPlugin/IdleCredentialStore.swift Starting execution
AWSCognitoAuthPlugin/IdleCredentialStore.swift Sending event CredentialStoreEvent.moveToIdleState
AWSCognitoAuthPlugin/LoadCredentialStore.swift Starting execution
AWSCognitoAuthPlugin/LoadCredentialStore.swift Retreiving credential asfDeviceId(username: "unknown")
[KeychainStore] Initialized keychain with service=com.amplify.awsCognitoAuthPlugin, attributes=KeychainStoreAttributes(itemClass: "genp", service: "com.amplify.awsCognitoAuthPlugin", accessGroup: nil), accessGroup=
[KeychainStore] Started retrieving `Data` from the store with key=authConfiguration
Credential Store state change:
{
"CredentialStoreState.error" = {
errorType = "KeychainStoreError: Unable to find the keychain item";
};
}
Credential Store state change:
{
"CredentialStoreState.idle" = {
};
}
Credential Store state change:
{
"CredentialStoreState.loadingStoredCredentials" = {
};
}
[KeychainStore] Successfully retrieved `Data` from the store with key=authConfiguration
[KeychainStore] Started setting `Data` for key=authConfiguration
[KeychainStore] Initialized fetching to decide whether update or add
[KeychainStore] Found existing item, updating
[KeychainStore] Successfully updated `Data` in keychain for key=authConfiguration
[KeychainStore] Started retrieving `Data` from the store with key=amplify.eu-west-2_mQiFbuxB0.unknown.deviceASF
[KeychainStore] Successfully retrieved `Data` from the store with key=amplify.eu-west-2_mQiFbuxB0.unknown.deviceASF
AWSCognitoAuthPlugin/LoadCredentialStore.swift Sending event CredentialStoreEvent.completedOperation
AWSCognitoAuthPlugin/IdleCredentialStore.swift Starting execution
AWSCognitoAuthPlugin/IdleCredentialStore.swift Sending event CredentialStoreEvent.moveToIdleState
Credential Store state change:
{
"CredentialStoreState.success" = {
savedData = "AWSCognitoAuthPlugin.CredentialStoreData.asfDeviceId(\"2635C31B-6F90-4CD6-B3E6-F777DB746DB5\", \"unknown\")";
};
}
Credential Store state change:
{
"CredentialStoreState.idle" = {
};
}
AWSCognitoAuthPlugin/InitializeHostedUISignIn.swift Sending event HostedUIEvent.showHostedUI
AWSCognitoAuthPlugin/ShowHostedUISignIn.swift Starting execution
Auth state change:
{
"AuthState.configured" = {
"AuthenticationState.signingIn" = {
"SignInState.signingInWithHostedUI" = {
"HostedUISignInState.showingUI" = {
};
};
};
"AuthorizationState.configured" = {
};
};
}
AWSCognitoAuthPlugin/ShowHostedUISignIn.swift Sending event SignInEvent(data: nil, id: "D9D78D98-8C60-4975-B6E1-EB6285BCEC61", eventType: AWSCognitoAuthPlugin.SignInEvent.EventType.throwAuthError(AWSCognitoAuthPlugin.SignInError.hostedUI(AWSCognitoAuthPlugin.HostedUIError.signInURI)), time: nil)
Checking next step for: signingInWithHostedUI(AWSCognitoAuthPlugin.HostedUISignInState.showingUI(AWSCognitoAuthPlugin.HostedUISigningInState(signInURL: REDACTED/oauth2/authorize?response_type=code&code_challenge_method=S256&client_id=REDACTED&state=f5cba9b0-aea0-4f63-a127-b91fff6b1b17&redirect_uri=REDACTED&scope=email%20openid%20profile&code_challenge=REDACTED&identity_provider=Auth0, state: "f5cba9b0-aea0-4f63-a127-b91fff6b1b17", codeChallenge: "REDACTED", presentationAnchor: Optional(<UIWindow: 0x103e0ba70; frame = (0 0; 393 852); gestureRecognizers = <NSArray: 0x600000c7c030>; layer = <UIWindowLayer: 0x600000c56eb0>>), options: AWSCognitoAuthPlugin.HostedUIOptions(scopes: ["email", "openid", "profile"], providerInfo: AWSCognitoAuthPlugin.HostedUIProviderInfo(authProvider: Optional(Amplify.AuthProvider.custom("Auth0")), idpIdentifier: nil), presentationAnchor: Optional(<UIWindow: 0x103e0ba70; frame = (0 0; 393 852); gestureRecognizers = <NSArray: 0x600000c7c030>; layer = <UIWindowLayer: 0x600000c56eb0>>), preferPrivateSession: false))))
Ok, I have this working now. It looks like it was my fault, I had the WebDomain property slightly wrong. So the problem was mine.
I guess some more helpful feedback from Amplify would be useful, rather than just not have the WebUI appear. But other than that I think my problem is solved. Thanks for the help! :)
Hi @januaryblues! I was just about to comment that based on the last log:
AWSCognitoAuthPlugin/ShowHostedUISignIn.swift Sending event SignInEvent(data: nil, id: "D9D78D98-8C60-4975-B6E1-EB6285BCEC61", eventType: AWSCognitoAuthPlugin.SignInEvent.EventType.throwAuthError(AWSCognitoAuthPlugin.SignInError.hostedUI(AWSCognitoAuthPlugin.HostedUIError.signInURI)), time: nil)
there was probably something wrong in your redirect URL. I'm happy to hear that was indeed the issue and that now everything works for you, and I apologize for not coming back to you sooner.
You're right that the lack of an error being thrown is something we need to address in our side, so we'll keep this issue open to track that work and to post further updates.
Thanks!
Please use the latest version, a fix for better error handling has been released.
This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.