Skip to content

Commit e75435b

Browse files
committed
Add Octopus - Authenticate w/ OIDC step template
1 parent 613537a commit e75435b

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"Id": "97a36fb9-7b00-4608-866f-53fd459bcdea",
3+
"Name": "Octopus - Authenticate with OIDC",
4+
"Description": "**This step requires Octopus 2025.3.12525 or later.**\n<br /><br />\nThis step uses Octopus an [OpenID Connect](https://octopus.com/docs/infrastructure/accounts/openid-connect) Account to obtain an access token that can be used in place of an API key in requests against the Octopus API.\n<br /><br />\nThe access token is stored in an [Output Variable](https://octopus.com/docs/projects/variables/output-variables) named **AccessToken**.",
5+
"ActionType": "Octopus.Script",
6+
"Version": 1,
7+
"Packages": [],
8+
"GitDependencies": [],
9+
"Properties": {
10+
"OctopusUseBundledTooling": "False",
11+
"Octopus.Action.Script.ScriptSource": "Inline",
12+
"Octopus.Action.Script.Syntax": "PowerShell",
13+
"Octopus.Action.Script.ScriptBody": "$server = $OctopusParameters[\"AuthenticateWithOIDC.ServerUri\"]\n$serviceAccountId = $OctopusParameters[\"AuthenticateWithOIDC.OidcAccount.Audience\"]\n$jwt = $OctopusParameters[\"AuthenticateWithOIDC.OidcAccount.OpenIdConnect.Jwt\"]\n\nfunction Invoke-OctopusApi {\n param(\n $Uri,\n $Method,\n $Body\n )\n\n try {\n Write-Verbose \"Making request to $Uri\"\n\n if ($null -eq $Body)\n {\n Write-Verbose \"No body to send in the request\"\n return Invoke-RestMethod -Method $method -Uri $Uri -ContentType \"application/json; charset=utf-8\"\n } \n\n $Body = $Body | ConvertTo-Json -Depth 10\n Write-Verbose $Body\n \n return Invoke-RestMethod -Uri $Uri -Method $Method -Body $Body -ContentType \"application/json; charset=utf-8\" -ErrorAction Stop\n }\n catch {\n Write-Host \"Request failed with message `\"$($_.Exception.Message)`\"\"\n\n if ($_.Exception.Response) {\n $code = $_.Exception.Response.StatusCode.value__\n $message = $_.Exception.Message\n Write-Host \"HTTP response code: $code\"\n\n Write-Host \"Server returned: $error\"\n }\n\n Fail-Step \"Failed to make $method request to $uri\"\n }\n}\n\nif ([string]::IsNullOrWhiteSpace($server)) {\n Fail-Step \"Octopus Server Uri is required.\"\n}\n\nif ([string]::IsNullOrWhiteSpace($OctopusParameters[\"AuthenticateWithOIDC.OidcAccount\"])) {\n Fail-Step \"OIDC Account is required.\"\n}\n\n$body = @{\n grant_type = \"urn:ietf:params:oauth:grant-type:token-exchange\";\n audience = \"$serviceAccountId\";\n subject_token_type = \"urn:ietf:params:oauth:token-type:jwt\";\n subject_token = \"$jwt\"\n}\n\n$uri = \"$server/.well-known/openid-configuration\"\n$response = Invoke-OctopusApi -Uri $uri -Method \"GET\"\n$response = Invoke-OctopusApi -Uri $response.token_endpoint -Method \"POST\" -Body $body\n\nSet-OctopusVariable -name \"AccessToken\" -value $response.access_token -sensitive\n"
14+
},
15+
"Parameters": [
16+
{
17+
"Id": "057c4820-9052-4d87-860e-4f4ef501fd4a",
18+
"Name": "AuthenticateWithOIDC.ServerUri",
19+
"Label": "Octopus Server Uri",
20+
"HelpText": "The URI of the Octopus Server with which to authenticate.",
21+
"DefaultValue": "#{Octopus.Web.ServerUri}",
22+
"DisplaySettings": {
23+
"Octopus.ControlType": "SingleLineText"
24+
}
25+
},
26+
{
27+
"Id": "dbcea301-baeb-4ae5-974e-3161695df254",
28+
"Name": "AuthenticateWithOIDC.OidcAccount",
29+
"Label": "OIDC Account",
30+
"HelpText": "The Generic OIDC Account variable used to authenticate with the Octopus Server.",
31+
"DefaultValue": "",
32+
"DisplaySettings": {
33+
"Octopus.ControlType": "GenericOidcAccount"
34+
}
35+
}
36+
],
37+
"StepPackageId": "Octopus.Script",
38+
"$Meta": {
39+
"ExportedAt": "2025-09-02T21:56:43.519Z",
40+
"OctopusVersion": "2025.3.13248",
41+
"Type": "ActionTemplate"
42+
},
43+
"LastModifiedBy": "ryanrousseau",
44+
"Category": "octopus"
45+
}

0 commit comments

Comments
 (0)