Skip to content

Amplify Auth - apps log each other out #4083

@dcristolovean

Description

@dcristolovean

Describe the bug

Assume I have 2 apps, from the same code base, using Amplify for Auth. The Auth Plugin is configured in code, not with a json file, with various values for each app. Everything works OK for years.
But it seems there's an issue with the keychain authconfiguration that result in apps logging each other out:

  1. Start app A -> login -> close -> restart -> all Good, user is still logged in, session OK
  2. Start app B -> login -> close -> start app A -> user no longer logged in. the fetchAuthSession.isSignedIn is suddenly false.

I enabled verbose logging and I'm seeing things like this, MANY TIMES, for both apps.

[KeychainStore] Initialized keychain with service=com.amplify.awsCognitoAuthPlugin, attributes=KeychainStoreAttributes(itemClass: "genp", service: "com.amplify.awsCognitoAuthPlugin", accessGroup: nil), accessGroup=No access group specified
[KeychainStore] Started retrieving Data from the store with key=authConfiguration
Starting execution for Auth.fetchSessionAPI
Starting execution
[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

At the same time, I see also KeyChain inits with the correct bundle id:

[KeychainStore] Initialized keychain with service=Optional("CORRECT BUNDLE FOR APP A or B").AWSMobileClient, attributes=KeychainStoreAttributes(itemClass: "genp", service: "Optional("CORRECT BUNDLE FOR APP A or ").AWSMobileClient", accessGroup: nil), accessGroup=No access group specified
[KeychainStore] Started retrieving Data from the store with key=loginsMap
[KeychainStore] No Keychain item found for key=loginsMap
[KeychainStore] Initialized keychain with service=Optional("CORRECT BUNDLE FOR APP A or ").AWSMobileClient, attributes=KeychainStoreAttributes(itemClass: "genp", service: "Optional("CORRECT BUNDLE FOR APP A or ").AWSMobileClient", accessGroup: nil), accessGroup=No access group specified
[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

Not sure but it seems all the keychain operations using the service = my 2 bundle ids are failing and only the generic one finds stuff.

Of course, if that's the case, app B puts different data there and kills the login for app A.

I don't need any Keychain Sharing, these are individual apps that I just need to stay logged in and I need to be able to install all of them if needed (there are way more than app A or app B, with different bundles of course.).
It's a sort of 'template' code, with just one target and various schemes + build scripts per client.

How can I be sure that one app doesn't overwrite the authConfig from the other app ? To be honest, I expected this to be done automatically.

LATER EDIT: I found one way this works and only one way: In the entitlements file for each app, if I put by hand the bundle id (no team, no nothing, just the bundle id) for the Keychain Access Group, it works perfectly. Each app has the same bundle.
If I add the Team ID in front, as it's recommended, so, TEAMID.BUNDLEID -> doesn't work (team id is the same for App A and App B). I tried with AccessGroup from the doc, it's completely useless, doesn't do anything.
I even tried with the "KeyChain": "service": .... in the AuthCategoryConfiguration json, doesn't do anything.

It doesn't even work without keychain sharing, removing the entitlements value and using/or not the AccessGroup.none.

So I'm out of ideas, wasted 2 full days on this. Why does it work with the bundle id in the entitlement ?

Steps To Reproduce

Kinda hard, you need 2 apps.  Let me know if my description was enough or if you need more info.

Expected behavior

Each app should save it's own authConfig and not interfere with one another.

Amplify Framework Version

2.51.1

Amplify Categories

Auth

Dependency manager

Swift PM

Swift version

5.x

CLI version

12.14.0 - not using it anyway

Xcode version

26.0.1

Platforms

iOS

OS Version

26.0.1

Device

any iPhone/sim

Specific to simulators

no

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