繁体   English   中英

如何使用 API 密钥访问 gradle 中工件上的 maven 存储库?

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

我们有一个 JFrog 工件,其中包含一个 maven 存储库(和其他元素)。

在我的 gradle 设置中,我定义了这个:

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

工作正常。 当我更改密码条目以使用我的 JFrog API KEY时,它也可以工作。

但是:使用 api 密钥仅在username包含我的真实用户 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.

问题是:在我们的设置中,我们手头有 API 密钥,但没有用户 ID。 所以我希望能够在没有用户名的情况下在 gradle 中定义一个 maven 依赖项。

但当

  • 我在 gradle 设置中将用户名留空,gradle 抱怨它是 null。
  • 除了我的真实用户 ID 外,我尝试其他任何方法,我得到401 Unauthorized响应

问题:是否可以在 gradle 中使用与 API KEYS 一起使用且不需要相应用户 ID 的“maven 风格”存储库定义?

Artifactory supports header based authentication where you provide the API key in the header X-JFrog-Art-Api (see Artifactory REST API ). 我手头没有要测试的 Artifactory 实例,但 Gradle 的HTTP header 身份验证应该可以解决问题:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM