Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Authentication Fail When Trying to Add Package to My Project via HTTPS with Swift Package Manager

Tags:

In my Xcode settings, I'm logged into my GitHub account (where 2fa is turned on) as a Source Control Account. I currently have it set up to use SSH and my SSH key. I've created an access token and securely saved that string on my machine. I can successfully add the package when I use an SSH URL (which makes sense, such as [email protected]:{username}/{repo_name}.git.

I can't get adding via HTTPS to work for some reason. It always results in the following error:

Error while fetching remote repository: https://github.com/{username}/{repo_name}.git

Authentication failed because no credentials were provided.

Is this a known Xcode error? I haven't found an answer here on SO. Is it because I'm using 2FA? All the packages have the same instruction which is essentially "Just copy and paste this URL into SPM to add" but that's never worked for me.

Would love some insight here. Thanks!

like image 515
Zack Shapiro Avatar asked Jun 05 '20 21:06

Zack Shapiro


People also ask

How do I add a swift package to an existing project?

To add the URL to your project: Tap or click the Add Document button (+) in the toolbar above the project navigator. Tap or click the menu and choose Swift Package. Enter the URL for your Swift package in the text field that appears, then tap or click Return.

How do I install swift package manager?

To create a new Swift package, open Xcode and select File > New > Swift Package. Choose a name and select a file location. Select “Create Git repository on my Mac” to put your package under version control. On completion, the Swift package opens in Xcode and looks similar to a standard Xcode project.

Does Swift package manager support iOS?

The Swift Package Manager can be used to add external libraries in Xcode projects. This makes the tool a good alternative to Cocoapods and Carthage for managing the dependencies of an iOS project.

What is a swift package?

Swift packages are reusable components of Swift, Objective-C, Objective-C++, C, or C++ code that developers can use in their projects. They bundle source files, binaries, and resources in a way that's easy to use in your app's project. Each Swift package requires a Package.


1 Answers

We solved this by removing a problematic setting in $HOME/.gitconfig:

Deleting:

[url "[email protected]:"]
    insteadOf = https://github.com/
like image 66
Paul Beusterien Avatar answered Sep 27 '22 16:09

Paul Beusterien