rest - Powershell Invoke-RestMethod Call using Windows store certificate (Basic Authorization ?) -
i call remote rest web service windows server hosting remote certificate. i've exported certificate remote server , added windwos store. (/personal/mycert)
i use on invoke-restmethod powershell command. here bellow code i've tried
# variables $remote_uri = "https://remote.example.com/service/search" $remote_certificatename = "mycert" $remote_apikey = "oisdjfsoedjfkqdfsdkfjsqdkfj" $remote_contenttype = "application/json" $localartifactpath = "c:\remoteobjects.json" # certificate $remote_certificatethumbprint = (get-childitem -path cert:\localmachine\my | where-object {$_.subject -match $remote_certificatename}).thumbprint; $certificate = get-childitem -path cert:\localmachine\my\$remote_certificatethumbprint # basic encoding $encoding = [system.text.encoding]::ascii.getbytes($certificate) $encodedstring = [system.convert]::tobase64string($encoding) $basicauth = "basic " + $encodedstring # set headers $headers = new-object "system.collections.generic.dictionary[[string],[string]]" $headers.add("authorization", $basicauth) $headers.add("api", $remote_apikey) $headers.add("content-type", $remote_contenttype) # self-signed certificate [system.net.servicepointmanager]::servercertificatevalidationcallback = { $true } # call rest service invoke-restmethod -method -uri $remote_uri -outfile $localartifactpath -headers $headers invoke-restmethod -method -uri $remote_uri -outfile $localartifactpath -certificate $certificate invoke-restmethod -method -uri $remote_uri -outfile $localartifactpath -certificatethumbprint $remote_certificatethumbprint # self-signed certificate off [system.net.servicepointmanager]::servercertificatevalidationcallback = $null the 3 lines invoke-restmethod commands failed respectively :
- wrong header (this expected gave try)
- authorization empty or scheme not basic
- certificate thumbprint not found
i've got rest call working @{"authorization"="basic base64encode(user:pass)"} can tell service answering not use user:pass in script.
i use certificate i've added windows store. i'm wondering 2 things :
- is "basic" authorization scheme 1 use certificate ?
- in powershell, how use certificate local windows store running invoke-restmethod command ?
thank help
Comments
Post a Comment