cmaroney
cmaroney

Reputation: 283

xcode 9.3 session expires every time i close and re-open Xcode

i am seeing my account show "Your session has expired. Please log in." in Xcode->Preferences->Accounts every time i restart Xcode, even though I log in successfully in-between restarts. Also, my command line xcodebuild is failing because it says the user session has expired.

We tried deleting and re-adding the user, and it did not solve the issue. We turned off 2-factor auth and turned it back on, and it also did not solve the issue, although we were seeing it allow the login w/o 2-factor auth for a while, until we turned it off and back on again, and then it started asking for a code again.

has anyone seen this behavior?

Upvotes: 23

Views: 5641

Answers (4)

PatrickDotStar
PatrickDotStar

Reputation: 1794

Apple just released Xcode 9.3.1 which should fix the issue. From the release notes:

Fixed an issue causing the user to have to log in with their Apple ID repeatedly. (39573406)

Upvotes: 4

itai195
itai195

Reputation: 1261

Xcode 9.3 now uses Keychain Access Groups to store your Apple ID credentials in the keychain. On launch, it attempts to migrate any existing credentials from previous versions of Xcode into the access group. In some cases, that migration appears to fail.

You likely don't need to install older versions of Xcode to work around this. If you remove your accounts from Xcode; quit Xcode; open Keychain Access; find and delete any "Xcode-Token" or "Xcode-AlternateDSID" entries; relaunch Xcode; and add your accounts back, then your accounts should work properly in Xcode 9.3 from that point on.

If you are capable of reproducing this issue, I'd like to request that you file a bug at bugreport.apple.com and attach a sysdiagnose from your machine.

Update

Thanks to everyone who filed bug reports! We've identified the issue and apologize for the inconvenience this is causing. In the meantime, you can avoid this problem by setting a user default. In Terminal, enter this command:

defaults write com.apple.dt.Xcode DVTDeveloperAccountUseKeychainService -bool NO

Then relaunch Xcode and reauthenticate your Apple ID accounts in the Accounts preference pane if necessary. From that point, you should be able to quit and relaunch Xcode without needing to reauthenticate each time.

Upvotes: 29

Frank
Frank

Reputation: 11

Because my account was new here, I cannot just add a commit to support @TendrilSix.

TendrilSix's answer above could solve the problem. If you're facing the same issue, just install Xcode 8.3.3 back, and log in your dev account inside Xcode 8.3.3.

The most IMPORTANT thing,

If Apple didn't fix this issue in future. DO NOT UNINSTALL XCODE 8.3.3.

We found on our dev machines, this problem only happened on mac which once has both Xcode 8.x and 9.x installed together.

After uninstalling Xcode 8.3.3, Dev accounts login freshly in Xcode 9.x will experience "Your session has expired. Please log in."

If a mac once had both 8.3.3 and 9.3 installed.

Only log in 8.3.3 was available, the login behavior will add 17 items in Keychain. Including "Xcode-Token" & "Xcode-AlternateDSID"

Log in 9.3 will only create 15 items in Keychain. Missing "Xcode-Token" & "Xcode-AlternateDSID"

If a mac upgrade from Xcode 7.x 8.x 9.x and never has two or more different version of Xcode installed together.

Log in 9.3 will create 17 items in Keychain, and dev account works properly.

Upvotes: 1

TendrilSix
TendrilSix

Reputation: 136

After going through a long list of things to try to fix this error (created new user, 2FA on/off, sign in/out iCloud, restored keychain, copied user off another machine etc.) without success, I tried a long shot.

Given that I only see this problem on fresh install High Sierra machines with a brand new install of the latest Xcode (upgrades seem fine), I wondered if the issue is visible in previous versions.

As I had the Xcode 8.3.3.xip on the network, I unpacked, installed and launched. It had the same expired session issue so I signed in again (the process was slightly clunky but worked) and then quit Xcode and relaunched. After the second attempt, not only did the session persist in version 8.3.3 but much to my surprise, Xcode version 9.3 now works fine too.

So my suggestion is to go to Apple Developer and login and then go to See More Downloads and get a previous version and try that. The 8.3.3 file I used can be downloaded from there. I didn't delete my existing 9.3 install, I simply renamed the unpacked 8.3.3 version to an alternate name and had both sitting alongside each other in /Applications allowing me to repeatedly launch each in turn for testing.

Upvotes: 5

Related Questions