如何与PowerShell(cyphertrust)连接到我的REST API

发布于 2025-01-23 04:35:26 字数 684 浏览 0 评论 0原文

我正在寻找如何使用PowerShell脚本连接到我的REST API

,我知道我需要使用Post方法发送我的身体,但不能定义如何做到这一点,

有文档他们在谈论代币:

这是我需要的。 方法打电话

https://10.75.8.128/playground_v2/api/Tokens#/v1/auth/tokens/-post

,我需要发送那个机构:

{
  "grant_type": "password",
  "username": "steve",
  "password": "mysecretword",
  "labels": [
    "myapp",
    "cli"
  ]
}

我尝试过,但它不起作用

$person = @{
  "grant_type": "password",
  "username": "username",
  "password": "MDP",
  "labels": [
    "myapp",
    "cli"
  ]
}

用Invoke rest

$person "https://10.75.8.128/playground_v2/api/v1/auth/tokens" -Method Post 

I am searching for how to connect to my rest API with a Powershell script

I know that I need to send my Body with the POST Method but can't define how to do it

There is documentation where they talk about tokens:

Its what I need to call with Invoke Rest-Method

https://10.75.8.128/playground_v2/api/Tokens#/v1/auth/tokens/-post

And there is that body that I need to send :

{
  "grant_type": "password",
  "username": "steve",
  "password": "mysecretword",
  "labels": [
    "myapp",
    "cli"
  ]
}

I tried this but it doesn't work

$person = @{
  "grant_type": "password",
  "username": "username",
  "password": "MDP",
  "labels": [
    "myapp",
    "cli"
  ]
}

Invoke-RestMethod

$person "https://10.75.8.128/playground_v2/api/v1/auth/tokens" -Method Post 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不必在意 2025-01-30 04:35:26

下面的代码对我来说很好:

$username = "admin"
$password = "password"
$Url = "https://$ciphertrust-manager-ip/api/v1/auth/tokens"
$Body = @{
    grant_type = "password"
    username = $username
    password = $password
    labels = @('myApp', 'cli')
}
$response = Invoke-RestMethod -Method 'Post' -Uri $Url -Body $body
$jwt = $response.jwt

从CipherTrust Manager收到的JSON响应中获得了JWT令牌。

希望这会有所帮助。

旁注:我不确定是否需要...我确实创建了一个示例PowerShell脚本来在CipherTrust Manager上执行一些复杂的API操作,否则该脚本将需要相当多的基于UI的步骤。 github链接

Below code worked for me just fine:

$username = "admin"
$password = "password"
$Url = "https://$ciphertrust-manager-ip/api/v1/auth/tokens"
$Body = @{
    grant_type = "password"
    username = $username
    password = $password
    labels = @('myApp', 'cli')
}
$response = Invoke-RestMethod -Method 'Post' -Uri $Url -Body $body
$jwt = $response.jwt

Got the jwt token back from the JSON response received from Ciphertrust Manager.

Hope this helps.

side note: I am not sure if it is required... I did create a sample powershell script to perform a few complex API operations on ciphertrust manager that would otherwise require quite a few UI based steps. GitHub Link Here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文