· 5 years ago · Apr 13, 2020, 01:24 PM
1function New-JWT (
2 [Parameter(Mandatory = $True)]
3 [ValidateSet("HS256", "HS384", "HS512")]
4 $Algorithm = $null,
5 $type = $null,
6 [Parameter(Mandatory = $True)]
7 [string]$Issuer = $null,
8 [int]$ValidforSeconds = $null,
9 [Parameter(Mandatory = $True)]
10 $SecretKey = $null
11 ){
12
13 $exp = [int][double]::parse((Get-Date -Date $((Get-Date).addseconds($ValidforSeconds).ToUniversalTime()) -UFormat %s)) # Grab Unix Epoch Timestamp and add desired expiration.
14
15 [hashtable]$header = @{alg = $Algorithm; typ = $type}
16 [hashtable]$payload = @{iss = $Issuer; exp = $exp}
17
18 $headerjson = $header | ConvertTo-Json -Compress
19 $payloadjson = $payload | ConvertTo-Json -Compress
20
21 $headerjsonbase64 = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($headerjson)).Split('=')[0].Replace('+', '-').Replace('/', '_')
22 $payloadjsonbase64 = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($payloadjson)).Split('=')[0].Replace('+', '-').Replace('/', '_')
23
24 $ToBeSigned = $headerjsonbase64 + "." + $payloadjsonbase64
25
26 $SigningAlgorithm = switch ($Algorithm) {
27 "HS256" {New-Object System.Security.Cryptography.HMACSHA256}
28 "HS384" {New-Object System.Security.Cryptography.HMACSHA384}
29 "HS512" {New-Object System.Security.Cryptography.HMACSHA512}
30 }
31
32 $SigningAlgorithm.Key = [System.Text.Encoding]::UTF8.GetBytes($SecretKey)
33 $Signature = [Convert]::ToBase64String($SigningAlgorithm.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($ToBeSigned))).Split('=')[0].Replace('+', '-').Replace('/', '_')
34
35 $token = "$headerjsonbase64.$payloadjsonbase64.$Signature"
36 $token
37}
38
39
40function Get-ZoomUsers {
41
42 [cmdletBinding()]
43 param(
44 [Parameter(Mandatory=$true)][String]$token
45 )
46
47 $headers = @{"Authorization" = "Bearer $token"}
48
49 $BaseUri = 'https://api.zoom.us/v2/users'
50 $Uri = $BaseUri + "?page_size=500&page_number=$page_number&status=active"
51 $UserList = Invoke-RestMethod -Method Get -Uri $Uri -Headers $headers
52
53 $UserList
54 #Sleep -Seconds .2
55}
56
57
58function Get-ZoomUser {
59
60 [cmdletBinding()]
61 param(
62 [Parameter(Mandatory=$true)][String]$token,
63 [Parameter(Mandatory=$true)][String]$UserId
64 )
65
66 $headers = @{"Authorization" = "Bearer $token"}
67
68 $Uri = "https://api.zoom.us/v2/users/$UserId"
69 $User = Invoke-RestMethod -Method Get -Uri $Uri -Headers $headers
70
71 $User
72 #Sleep -Seconds .2
73}
74
75
76function Set-ZoomUserStatus {
77
78 [cmdletBinding()]
79 param(
80 [Parameter(Mandatory=$true)][String]$token,
81 [Parameter(Mandatory=$true)][String]$UserId,
82 [Parameter(Mandatory=$true)][String]$status #activate or deactivate
83 )
84
85 $headers = @{"Authorization" = "Bearer $token"}
86
87 $Uri = "https://api.zoom.us/v2/users/$userId/status"
88
89 $StatusJson = @"
90{
91 "action": "$status"
92}
93"@
94
95 Invoke-RestMethod -Method Put -Uri $Uri -Headers $headers -body $StatusJson -ContentType application/json
96
97}
98
99
100function Get-ZoomDelegates {
101
102 [cmdletBinding()]
103 param(
104 [Parameter(Mandatory=$true)][String]$token,
105 [Parameter(Mandatory=$true)][String]$userId
106 )
107
108 $headers = @{"Authorization" = "Bearer $token"}
109
110 $Uri = "https://api.zoom.us/v2/users/$userId/assistants"
111
112 #$Uri = $BaseUri + "?page_size=500&page_number=$page_number&status=active"
113
114 $Delegates = Invoke-RestMethod -Method Get -Uri $Uri -Headers $headers
115
116 $Delegates
117
118}
119
120
121function Set-ZoomDelegate {
122
123# Set-ZoomDelegate -token $token -userId "uahdkamDJka28ren" -AssistantId "9FGvpuJMTs-XnGSQxftXiw" -AssistantEmail "user@blueprintmedicines.com"
124
125 [cmdletBinding()]
126 param(
127 [Parameter(Mandatory=$true)][String]$token,
128 [Parameter(Mandatory=$true)][String]$userId,
129 [Parameter(Mandatory=$true)][String]$AssistantId,
130 [Parameter(Mandatory=$true)][String]$AssistantEmail
131 )
132
133 $headers = @{"Authorization" = "Bearer $token"}
134
135 $Uri = "https://api.zoom.us/v2/users/$userId/assistants"
136
137 #Create Assistant Json
138 $AssistantJson = @"
139{
140 "assistants": [
141 {
142 "id": "$AssistantId",
143 "email": "$AssistantEmail"
144 }
145 ]
146}
147"@
148
149 Invoke-RestMethod -Method POST -Uri $Uri -Headers $headers -body $AssistantJson -ContentType "application/json"
150
151}