swift-package-manager: Xcode 15.1 - not able to add private package dependencies to app project

Description

We are hosting Swift package using https://jfrog.com/help/r/jfrog-artifactory-documentation/swift-registry. Registry is protected and requires authentication. Swift registry works fine using CLI.

When I add a dependency to an application project from Xcode UI (File -> Add package dependency)or via this UI: Screenshot 2024-01-08 at 7 00 01 PM

Xcode displays error “Authentication failed because the credentials were rejected”

Screenshot 2024-01-09 at 10 55 14 AM

Xcode is able to resolve the same private package dependency just fine if I add dependency to a Swift package project via Package.swift" Screenshot 2024-01-09 at 11 28 10 AM

My registries.json:

{
  "authentication" : {
    "example.jfrog.io" : {
      "loginAPIPath" : "/artifactory/api/swift/swift-registry-local",
      "type" : "basic"
    }
  },
  "registries" : {
    "[default]" : {
      "supportsAvailability" : false,
      "url" : "https://example.jfrog.io/artifactory/api/swift/swift-registry-local"
    }
  },
  "version" : 1
}

I do have registry credentials stored on keychain. It is just one credentials set. Xcode asks to access registry creds on keychain and I grant the permission. I tested with both registry authentication types: basic and token. Both types of authentication fail when adding dependency package from Xcode UI.

Screenshot 2024-01-09 at 11 33 46 AM

Expected behavior

Xcode UI should allow adding protected package dependencies to application projects.

Actual behavior

Xcode displays authentication error when I attempt to add protected package dependency: Screenshot 2024-01-09 at 10 55 14 AM

Steps to reproduce

  1. Install Xcode 15.1
  2. Set up SPM registry that requires authentication (such as https://jfrog.com/help/r/jfrog-artifactory-documentation/swift-registry)
  3. Setup registry URL by command line: package-registry set --global “url”
  4. Setup registries auth by command line: package-registry login “url” --username “uname” --password “pwd”
  5. Verify registries.json file is created with appropriate authentication type.
  6. Verify appropriate Keychain Internet Password is created for registry host URL
  7. Open application project in Xcode and go to File->Add Package Dependencies…
  8. In the “Add Package” window, in the top right corner input field “Search or Enter Package URL” enter registry URL
  9. Xcode displays “Authentication failed because the credentials were missing” window asking to re-enter user name and password
  10. Reentering username/password does also fails with authentication error

Swift Package Manager version/commit hash

No response

Swift & OS version (output of swift --version ; uname -a)

swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5) Target: x86_64-apple-macosx13.0 Darwin 22.6.0 Darwin Kernel Version 22.6.0: Wed Oct 4 21:25:26 PDT 2023; root:xnu-8796.141.3.701.17~4/RELEASE_X86_64 x86_64

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 6
  • Comments: 19 (7 by maintainers)

Most upvoted comments

Would you be able to clarify if this issue is reproducible for you with swift build, swift test, or any other SwiftPM CLI commands?

SwiftPM CLI works just fine. Furthermore, Xcode is resolving our private package just fine if package is imported into another package via Package.swift. My test Package lists our private SPM package as dependency on Package.swift. The moment I open the test Package in Xcode, private dependency gets resolved and Package.resolved gets generated.

When I try to add private SPM package dependency to TestApp.xcodeproj via >File>Add Package Dependency> entering Jfrog registry URL in the Search box , this is when Xcode is not able to resolve the package.

What is the difference in how Xcode resolves packages listed on the Package.swift vs via manually resolving through “Add Package Dependency” ?

Could it be this? https://forums.developer.apple.com/forums/thread/729959 I fixed the issue by going to ~/.gitconfig and removing any reference to entries with [url "https://github.com/"] insteadOf = ... or [url "ssh://git@github.com/"]

EDIT: I also have the GitHub account in Xcode, as well as the entry in ~/.netrc.

Nope. We are not hosting private package on GitHub. It is hosted in Jfrog Swift Registry.

Very interested in this topic. @ncharniauski where you able to solve this issue ?

@gurelkaynak I did try your solution but I am still not able to retrieve the packages.

The configuration I tried:

  1. Setup the swift registry swift package-registry set --global "https://example.jfrog.io/artifactory/api/swift/swift-registry-local"

  2. Use the login command to store credential in keychain

swift package-registry login https://example.jfrog.io/artifactory/api/swift/swift-registry-local \
    --username myUser \
    --password myToken

with myUser my artifactory user and myToken the token provided by artifactory with the set me up action

Here is the registries.json than I am getting:

{
  "authentication" : {
    "example.jfrog.io" : {
      "loginAPIPath" : "/artifactory/api/swift/swift-registry-local",
      "type" : "basic"
    }
  },
  "registries" : {
    "[default]" : {
      "supportsAvailability" : false,
      "url" : "https://example.jfrog.io/artifactory/api/swift/swift-registry-local"
    }
  },
  "version" : 1
}

At this point I tried to search for my package in the search bar but not able to get anything.

Screenshot 2024-07-19 at 13 36 08

I tried to put as URL:

None of these solutions is working.

Okay, I dont know whether this is a bug or not. I tried putting this code snippet in user-level registries.json

// ~/.swiftpm/configurations/registries.json
{
  "authentication" : {
    "example.jfrog.io" : {
      "loginAPIPath" : "/artifactory/api/swift/swift-registry-local",
      "type" : "basic"
    }
  },
  "registries" : {
    "[default]" : {
      "supportsAvailability" : false,
      "url" : "https://example.jfrog.io/artifactory/api/swift/swift-registry-local"
    }
  },
  "version" : 1
}

and then quit xcode and reopen again and try to add package from Xcode UI it works perfectly 🎉

Unfortunately, this issue should be closed here then. This repository hosts the open-source SwiftPM project and its CLI, it does not track Xcode-specific issues. Please file anything Xcode-specific at https://feedbackassistant.apple.com.