GhostCat
GhostCat

Reputation: 140623

How to access a maven repo on artifactory in gradle using API key?

We have a JFrog artifactory that contains a maven repo (and other elements).

In my gradle setup, I defined this:

repositories {
    maven {
        url = uri("https://eu.artifactory....../whatever/")    
        credentials {
            username = "my-full-user-id"
            password = "my-real-password"
        }
    }
}

Works fine. It also works when I change the password entry to use my JFrog API KEY.

But: using the api key only works when username contains my real user id.

Whereas: when making https requests "directly" to JFrog (for example using a python script), it is not required to provide a user name: simply having the API KEY in the request header is enough.

Thing is: in our setup, we have the API key at hand, but not the user id. So I had hoped to be able to define a maven dependency in gradle that works without user names.

But when

Question: is it possible to use "maven style" repository definition in gradle that works with API KEYS and that doesn't need the corresponding user ids?

Upvotes: 5

Views: 6506

Answers (2)

UltimateGeek
UltimateGeek

Reputation: 550

The answer with "Private-Token" does not work for me with Artifactory 7.41.

Instead, this is what worked:

    repositories {
        maven {
            url "http://<artifactory.server.fqdn>/artifactory/<maven-repo-name>"
            credentials(HttpHeaderCredentials) {
                name = "Authorization"
                value = "Bearer <token>"
            }
            authentication { header(HttpHeaderAuthentication) }
        }
    }

Upvotes: 2

Thomas K.
Thomas K.

Reputation: 6780

Artifactory supports header based authentication where you provide the API key in the header X-JFrog-Art-Api (see Artifactory REST API). I do not have an Artifactory instance at hand to test, but Gradle's HTTP header authentication should do the trick:

repositories {
    maven {
        url = uri("http://repo.mycompany.com/maven2")
        credentials(HttpHeaderCredentials::class) {
            name = "Private-Token"
            value = "TOKEN"
        }
        authentication {
            create<HttpHeaderAuthentication>("header")
        }
    }
}

Upvotes: 6

Related Questions