Skip to content

Sharing keychain between app and widget extension logs out user #4098

@dandreiolteanu

Description

@dandreiolteanu

Describe the bug

Hey guys, first of all thanks for making this happen, I am still struggling to use it as expected when having a Widget Extension.

  • Amplify version I am using is 2.51.5

Basically everything works as expected when I only have the main app and specify the access group with migrateKeychainItemsOfUserSession = true, I can still use the app and session is migrated -> user is not logged out.

As soon as I setup Amplify in the Widget Extension, I get logged out of the main app, something weird is happening and didn't quite figure out what, can you please help? @harsh62

If I start fresh installing the app and act as a new user, everything is working fine, but for users which already have the app installed it's not working.

The plan is to make a release in which we support shared keychain and add the widget extension, so there will be users logged out if this doesn't work properly, therefore making it impossible at the moment to release.

Attaching the setup code for the main app ⬇️

public func setup(application: UIApplication, launchOptions: [UIApplication.LaunchOptionsKey: Any]?, config: TiltCore.VendorConfig) {
        #if DEBUG
        Amplify.Logging.logLevel = .verbose
        #endif

        do {
            let configuration = try AmplifyConfiguration(
                configurationFile: AppConfiguration.current.amplify.configFileURL
            )
            let accessGroup = AccessGroup(
                name: AppConfiguration.current.vendor.appKeychainSharingIdentifier,
                migrateKeychainItemsOfUserSession: true
            )
            let secureStoragePrefernces = AWSCognitoSecureStoragePreferences(accessGroup: accessGroup)
            try Amplify.add(
                plugin: AWSCognitoAuthPlugin(
                    networkPreferences: AWSCognitoNetworkPreferences(maxRetryCount: 2, timeoutIntervalForRequest: 15),
                    secureStoragePreferences: secureStoragePrefernces
                )
            )
            try Amplify.add(plugin: AWSPinpointAnalyticsPlugin())
            try Amplify.add(plugin: AWSS3StoragePlugin())
            try Amplify.configure(configuration)
            Log.info("Amplify initialized successfully with Auth, Analytics, Storage")
        } catch {
            Log.error(category: .config, "Amplify init failed with \(error.localizedDescription)", error: error)
        }
    }

Attaching the setup code for the widget extension ⬇️

private func setupVendorAWS(configuration: TiltWidgetKitConfiguration) {
        #if DEBUG
        Amplify.Logging.logLevel = .verbose
        #endif

        do {
            let amplifyConfiguration = try AmplifyConfiguration(
                configurationFile: configuration.amplify.configFileURL
            )
            let accessGroup = AccessGroup(
                name: configuration.vendor.appKeychainSharingIdentifier,
                migrateKeychainItemsOfUserSession: true, false // tried both
            )
            let secureStoragePrefernces = AWSCognitoSecureStoragePreferences(accessGroup: accessGroup)
            try Amplify.add(
                plugin: AWSCognitoAuthPlugin(
                    networkPreferences: AWSCognitoNetworkPreferences(maxRetryCount: 2, timeoutIntervalForRequest: 15),
                    secureStoragePreferences: secureStoragePrefernces
                )
            )
            try Amplify.configure(amplifyConfiguration)
            Log.info(category: .widgetKit, "Amplify initialized successfully with Auth")
        } catch {
            Log.error(category: .widgetKit, "Amplify init failed with \(error.localizedDescription)", error: error)
        }
    }
  • note I've tried both migrateKeychainItemsOfUserSession = true or false with clean simulators

Steps To Reproduce

Steps to reproduce the behavior:
1. Add keychain sharing support to an already existing app (for a logged in user)
2. Add widget extension and use initialize amplify from there using the same keychain sharing
3. Run the app
4. User is logged out

Expected behavior

User session should be persisted in the main app and widget extension can fetch auth session same as the main app

Amplify Framework Version

2.51.5

Amplify Categories

Auth

Dependency manager

Swift PM

Swift version

5.10

CLI version

no idea

Xcode version

26.0.1

Relevant log output

Is this a regression?

No

Regression additional context

No response

Platforms

iOS

OS Version

iOS 26.0

Device

iPhone 17 Pro

Specific to simulators

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpending-triageIssue is pending triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions