23

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?

cmaroney
  • 283
  • 3
  • 9
  • I am seeing the same issue here with Xcode 9.3. It is happening on both my development machine and on our Xcode Server CI system. – Bennett Smith Apr 05 '18 at 16:28
  • I'm seeing the same issue, i have tried with a 2FA and non 2FA apple developer account, on XCode 9.3 – Jarrod Chesney Apr 07 '18 at 04:42
  • Getting exactly the same - did a fresh installation of High Sierra and every time I re-open XCode it says "Session Expired". If I login, it's fine, once I close XCode, the session is once again expired. – manosim Apr 07 '18 at 15:16

4 Answers4

29

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.

itai195
  • 1,261
  • 7
  • 6
  • 3
    Not working for me. Deleted all the "Xcode-Token" and "Xcode-AlternateDSID" entries. Still the same. – gogoout Apr 14 '18 at 09:02
  • 1
    i have run sysdiagnose and attached it to a bug report. – cmaroney Apr 17 '18 at 14:37
  • 2
    I opened a bug report as well - was asked to send a sysdiagnose and then they told me "It looks like your Xcode’s signature may be broken. Has the Xcode bundle been modified? What does `codesign —verify /path/to/Xcode.app` return?". I run the command but there was no output. FYI Installed Xcode from the app store after a fresh installation of Mac OS. – manosim Apr 19 '18 at 13:23
  • Thanks for this report! So great to have your direct feedback here. Between this and the runaway CPU issues, what's really needed is a new better version of Xcode! I'm sure you guys are working on it. – matt Apr 20 '18 at 16:31
  • 3
    `defaults write com.apple.dt.Xcode DVTDeveloperAccountUseKeychainService -bool NO` solved it for me. Many thanks! – Martin Pape Apr 21 '18 at 08:58
  • I had the same issue after changing my Apple-ID password. This easy fix does the trick for me. Thanks! – PatrickDotStar May 10 '18 at 15:23
  • @manosim This was a great suggestion. I had installed VIM as an extension. This is probably the issue. – SmileBot Aug 31 '20 at 20:11
5

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.

TendrilSix
  • 136
  • 3
4

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)

PatrickDotStar
  • 1,654
  • 1
  • 19
  • 20
1

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.

Frank
  • 11
  • 2