Home > Enterprise >  How to configure git to use access token in cocoapods specfiles?
How to configure git to use access token in cocoapods specfiles?

Time:10-21

I am working on an iOS project with cocoapods, which dependencies are in a GitHub Enterprise (GHE). The Podfile has a podspec repo source in it:

source 'https://git.xxx.com/xxx/podspec-ios.git'

In this repository are about 100 more podspec files in it. Every podspec source is using the https protocol, e.g.

[...]
s.source        = { :git => "https://git.xxx.com/xxx/module-xxx-ios.git"
[...]

Since I am an external freelancer and not directly connected to their network, I have to use SSH to login into the GHE.
When I am trying to install the pods, the CLI wants me to login. But I don't have any credentials (also there is a 2FA login for employees, which doesn't work in the cli). But I am able to create GHE Access Token. Where do I need to configure this? Is it my git cli? Or can I configure Cocoapods to use the Access Token?

CodePudding user response:

Assuming you're using GitHub, then access tokens are only for HTTPS. If you're using HTTPS, then you can set up a credential helper as documented in the Git FAQ. Note that where it says “password”, you should put your personal access token, not your password.

Otherwise, if you need to use SSH, all you have is an HTTPS URL, and you can't change the URL, then you can use Git's insteadOf feature in your ~/.gitconfig:

[url "[email protected]:"]
    insteadOf = "https://git.xxx.com/"

This will automatically rewrite URLs from HTTPS to SSH for that domain.

CodePudding user response:

The login prompt accepts the access token.

Initially it didn't work, because my password manager stored the token with a space at position 1.

  • Related