-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoauth-authentication.ps1
58 lines (50 loc) · 1.48 KB
/
oauth-authentication.ps1
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<#
# Version 1.0.0
# Copyright (c) 2021 by Mobinergy. All Rights Reserved.
#
# Author: [email protected]
#
# Get Workspace One ogranization group using APIs.
# OAuth Authentication
#>
######################################################
# Workspace One UEM API Information
######################################################
$apiHost = ''
$clientId = ''
$clientSecret = ''
$apiKey = ''
$tokenUrl = 'https://na.uemauth.vmwservices.com/connect/token'
######################################################
# Get access token
######################################################
$headers = @{
'Content-Type' = 'application/x-www-form-urlencoded'
}
$body = @{
'client_id' = $clientId
'client_secret' = $clientSecret
'grant_type' = "client_credentials"
}
try {
$response = Invoke-RestMethod $tokenUrl -Method 'POST' -Headers $headers -Body $body
$token = $response.access_token
$authorizationHeader = "Bearer ${token}"
} catch {
Write-Error $_.Exception.Message
}
######################################################
# Get organization groups
######################################################
$getOrgGroupsUrl = "https://$apiHost/API/system/groups/search"
$headers = @{
'Accept' = 'application/json;version=2'
'Authorization' = $authorizationHeader
'aw-tenant-code' = $apiKey
}
try {
$groupsResponse = Invoke-RestMethod -URI $getOrgGroupsUrl -Headers $headers
Write-Host $groupsResponse.OrganizationGroups
} catch {
Write-Error $_.Exception.Message
}