Downloading Binary-only Swift Packages that require authentication
Asked Answered
C

0

8

I am using the Swift Package Manager that is built into Xcode 13.1 (not the command line version that uses Package.swift).

One of my dependencies is a Binary-only package. Here is what the Package.swift of that package looks like:

// swift-tools-version:5.5

import PackageDescription

let package = Package(
    name: "MyLibrary",
    products: [
        .library(
            name: "MyLibrary",
            targets: ["MyLibrary"]),
    ],
    dependencies: [],
    targets: [
        .binaryTarget(
            name: "MyLibrary",
            url: "https://gitlab.example.com/api/v4/projects/85/packages/generic/mylibrary/1.0.1/MyLibrary.xcframework.zip",
            checksum: "..."
        )
    ]
)

The binary is stored in GitLab's Generic Package Repository.

I have added the Git repository that hosts the package to my "Package Dependencies" in my project. I have generated a Personal Access Token that has API and Repository access and added it to my .netrc file:

machine gitlab.example.com
login gitlab-token
password MY_TOKEN_HERE

When I run xcodebuild -resolvePackageDependencies or use "File" -> "Packages" -> "Resolve Package Versions" in the Xcode GUI, the Git repository is cloned successfully but I get the following error message:

failed downloading 'https://gitlab.example.com/api/v4/projects/85/packages/generic/mylibrary/1.0.1/MyLibrary.xcframework.zip' which is required by binary target 'MyLibrary': badResponseStatusCode(401)

I have tried adding the same credentials to the macOS Keychain to see if Xcode can pick them up from there, but I still see the same error.

In the Swift Package Manager CLI source code, I can see that it handles crednetials for binary downloads too, but it seems that Xcode does not.

Unfortunately, I cannot switch from Xcode-integrated packaging to Package.swift packaging because other developers on the project will be confused by it.

Is it possible to get Xcode to use the .netrc credentials for downloading the file too?


Note: Cross-posted to Apple Developer Forum

Comeuppance answered 4/11, 2021 at 3:53 Comment(4)
It might be something about GitLab not supporting that HTTP basic authentication or SPM not accepting some redirection that GitLab might do. See this related thread in Swift forums forums.swift.org/t/…Wain
Just today I got it working with the XCFrameworks being stored in a secured S3 bucket. What helped me to get it running was using Charles to see the actual request being made by Xcode. This way, at least you can check whether the issue comes from the Xcode or from GitLabWain
@Wain Thanks for the suggestion to try Charles. I will do that.Comeuppance
@Wain How did you manage to get XCFramework dependency from the secure S3 bucket? Which dependency manager have you used?Howlett

© 2022 - 2024 — McMap. All rights reserved.