forked from membrane/api-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.ps1
More file actions
38 lines (34 loc) · 1.21 KB
/
client.ps1
File metadata and controls
38 lines (34 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
param (
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$username,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$password
)
$clientId = "abc"
$clientSecret = "def"
$tokenEndpoint = "http://localhost:7007/oauth2/token"
$target = "http://localhost:2000"
function getToken{
Write-Host "1.) Requesting Token"
Write-Host "POST $tokenEndpoint"
$postParams = @{grant_type="password";username=$username;password=$password;client_id=$clientId;client_secret=$clientSecret}
Write-Host $postParams
Write-Host
return Invoke-WebRequest -Uri $tokenEndpoint -Method POST -Body $postParams | ConvertFrom-Json
}
function sendRequestToTarget($tokenResult){
Write-Host
Write-Host "2.) Calling API"
Write-Host "GET $target"
$headers = @{"Authorization"=$tokenResult.token_type + " " + $tokenResult.access_token}
Write-Host Authorization: $headers["Authorization"]
Write-Host
return Invoke-WebRequest -Uri $target -Headers $headers
}
$tokenEndpointResult = getToken
Write-Host "Got Token:" $tokenEndpointResult.access_token
Write-Host
$result = sendRequestToTarget $tokenEndpointResult
Write-Host "Got": $result.Content