Skip to content

Calling Auth.SignInWithWebUI results in nothing happening #3888

@januaryblues

Description

@januaryblues

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    authIssues related to the Auth categorybugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions