Skip to content

Commit

Permalink
error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
freddydk committed Jan 24, 2025
1 parent a0dc6d4 commit aebff0d
Showing 1 changed file with 1 addition and 29 deletions.
30 changes: 1 addition & 29 deletions Actions/Github-Helper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ function GetAccessToken {
return $realToken
}
catch {
throw "Invalid GitHub App token format"
throw "Error getting access token from GitHub App. The error was ($($_.Exception.Message))"
}
}
}
Expand Down Expand Up @@ -1199,31 +1199,3 @@ function DownloadArtifact {
return $filename
}
}

# Generate JWT for token request
# As documented here: https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-a-json-web-token-jwt-for-a-github-app
function GenerateJwtForTokenRequest {
Param(
[string] $gitHubAppClientId,
[string] $privateKey
)

$header = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes((ConvertTo-Json -InputObject @{
alg = "RS256"
typ = "JWT"
}))).TrimEnd('=').Replace('+', '-').Replace('/', '_');

$payload = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes((ConvertTo-Json -InputObject @{
iat = [System.DateTimeOffset]::UtcNow.AddSeconds(-10).ToUnixTimeSeconds()
exp = [System.DateTimeOffset]::UtcNow.AddMinutes(10).ToUnixTimeSeconds()
iss = $gitHubAppClientId
}))).TrimEnd('=').Replace('+', '-').Replace('/', '_');
$signature = pwsh -command {
$rsa = [System.Security.Cryptography.RSA]::Create()
$privateKey = "$($args[1])"
$rsa.ImportFromPem($privateKey)
$signature = [Convert]::ToBase64String($rsa.SignData([System.Text.Encoding]::UTF8.GetBytes($args[0]), [System.Security.Cryptography.HashAlgorithmName]::SHA256, [System.Security.Cryptography.RSASignaturePadding]::Pkcs1)).TrimEnd('=').Replace('+', '-').Replace('/', '_')
Write-OutPut $signature
} -args "$header.$payload", $privateKey
return "$header.$payload.$signature"
}

0 comments on commit aebff0d

Please sign in to comment.