PowerShell 的 Artifactory 基本身份验证抛出 403
我正在尝试从 powershell 向 JFROG 进行身份验证,我用我的令牌进行了尝试,结果出现 403 禁止
PS C:\Myproject> $myHeaders = @{'X-JFrog-Art-Api' = 'AKCp8sdFTEKF1Y5MDgM3M8RK6bRkKWoX43jWranZvS2U2DE82KFE7243F'}
PS C:\Myproject> Invoke-WebRequest -Uri "https://org.jfrog.io/" -Method Get -Headers $myHeaders
Invoke-WebRequest : 403 Forbidden
nginx
At line:1 char:1
+ Invoke-WebRequest -Uri "https://fiprod.jfrog.io/" -Method Get -Header ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
知道如何使用 PowerShell 通过令牌向 Artifactory 进行身份验证吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定这是否仍然需要,但也许会帮助其他人。在大多数情况下,基本用户无法创建 API 密钥,因此您只能选择仅使用需要与您的用户名关联的令牌 ID。
基于官方文档 https://jfrog.com/knowledge-base/artifactory-how-to-download-or-upload-a-file-from-to-artifactory-using-powershell/ ,您必须创建您的标头如下:
其中用户名是您的 JFrog 工件用户名,密码是您的身份验证令牌。
作为一个好的做法,这样您就不会在脚本中共享敏感信息,您可以在环境变量中添加用户和令牌,并且您可以从脚本中读取它们(假设将它们作为运行脚本是可能的)。
要使用这种方法,您可以执行以下操作:
其中 ARTIFACTORY_USER 和 ARTIFACTORY_PASSWORD 是保存 JFrog 工件凭证的环境变量,而 $artifactoryCredentials 变量只是创建身份验证标头格式所需的身份验证字符串,您将其合并到标头中像这样:
或者您可以将整个身份验证标头保存在另一个变量中。
Not sure if this is still needed but maybe will help others. In most cases basic users cannot create an API key, leaving you with the only option of using only the token ID which needs to be used in correlation with your username.
Based on the official documentation https://jfrog.com/knowledge-base/artifactory-how-to-download-or-upload-a-file-from-to-artifactory-using-powershell/ , you have to create your header as follows:
where username is your JFrog artifactory username and the password is your authentication token.
As a good practice so you do not share sensitive information in your script you could add the user and token in your environment variables, and you can just read them from there in your script (assuming that having them as environment variables on your machines running the script is possible).
To use this approach you could do something like this:
where ARTIFACTORY_USER and ARTIFACTORY_PASSWORD are the environment variables holding the credentials for your JFrog artifactory and the $artifactoryCredentials variable is just creating the authentication string required by the authentication header format which you will incorporate in the header like this:
or you can hold the entire authentication header in another variable.