Skip to content

Instantly share code, notes, and snippets.

@fabriciosanchez
Created April 10, 2020 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabriciosanchez/be47b83483c20a901640106b464b1af4 to your computer and use it in GitHub Desktop.
Save fabriciosanchez/be47b83483c20a901640106b464b1af4 to your computer and use it in GitHub Desktop.
Defining configuration for certificates in APIM.
# Specify cert configuration
$gatewayHostname = "api.americasuniversity.net"
$portalHostname = "portal.americasuniversity.net"
$gatewayCertCerPath = "C:\AmericasUniversity\certs\api\api.americasuniversity.net.cer"
$gatewayCertPfxPath = "C:\AmericasUniversity\certs\api\api.americasuniversity.net.pfx"
$portalCertPfxPath = "C:\AmericasUniversity\certs\portaldev\portal.americasuniversity.net.pfx"
$gatewayCertPfxPassword = "cert-api-password"
$portalCertPfxPassword = "cert-portal-password"
# Convert to secure string before send it over HTTP
$certPwd = ConvertTo-SecureString -String $gatewayCertPfxPassword -AsPlainText -Force
$certPortalPwd = ConvertTo-SecureString -String $portalCertPfxPassword -AsPlainText -Force
# Create and set the hostname configuration objects for the proxy and portal
$proxyHostnameConfig = New-AzApiManagementCustomHostnameConfiguration `
-Hostname $gatewayHostname `
-HostnameType Proxy `
-PfxPath $gatewayCertPfxPath `
-PfxPassword $certPwd
$portalHostnameConfig = New-AzApiManagementCustomHostnameConfiguration `
-Hostname $portalHostname `
-HostnameType Portal `
-PfxPath $portalCertPfxPath `
-PfxPassword $certPortalPwd
# Ties certificates confs into APIM service
$apimService.ProxyCustomHostnameConfiguration = $proxyHostnameConfig
$apimService.PortalCustomHostnameConfiguration = $portalHostnameConfig
# Updates the existing APIM with the updated configuration
Set-AzApiManagement -InputObject $apimService
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment