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?
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With