Created
September 28, 2021 09:40
-
-
Save joacar/5e88bea068a0c0d7b093f783bcb57657 to your computer and use it in GitHub Desktop.
Create certificates from OpenID well known configurations meta data by following the 'jwks_uri' and iterate the keys result.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param( | |
[Parameter(Mandatory = $True, Position=1)][string]$BaseUrl | |
) | |
function Get-Json { | |
Param([string]$json, [string]$key) | |
ConvertFrom-Json $json | Select-Object -expand $key | |
} | |
$configuration = Invoke-WebRequest -ContentType "application/json" -Uri "$BaseUrl/.well-known/openid-configuration" | |
$jwksUri = Get-Json $configuration.Content "jwks_uri" | |
$response = Invoke-WebRequest -ContentType "application/json" -Uri $jwksUri | |
$certificates = @{} | |
Get-Json $response.Content 'keys' | ForEach-Object { $certificates[$_.kid] = [string]$_.x5c } | |
$certificates.Keys | ForEach-Object { | |
$cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]([System.Convert]::FromBase64String($certificates[$_])) | |
$filePath = "${_}.crt" | |
Export-Certificate -Cert $cert -FilePath $filePath | |
Write-Host "Exported certificate '${cert}' to '${filePath}'" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment