moving to main PS repo
This commit is contained in:
parent
4a89deeebd
commit
492b7b7363
@ -1,52 +0,0 @@
|
|||||||
<#
|
|
||||||
Script to generate bearer token for Egnyte API. Bearer token is then used in future reqeusts.
|
|
||||||
#>
|
|
||||||
|
|
||||||
$BasePath = 'https://mpe.egnyte.com'
|
|
||||||
$OAuthPath = $BasePath + '/puboauth/token'
|
|
||||||
|
|
||||||
# Get path to store bearer.token file.
|
|
||||||
if (!($Tokenfolderpath)) {
|
|
||||||
Add-Type -AssemblyName System.Windows.Forms
|
|
||||||
$FileBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
|
|
||||||
$FileBrowser.Description = 'Locate bearer.token file'
|
|
||||||
$FileBrowser.UseDescriptionForTitle
|
|
||||||
$null = $FileBrowser.ShowDialog()
|
|
||||||
$Tokenfolderpath = $FileBrowser.SelectedPath
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$key_path = $Tokenfolderpath + '\Egnyte Key.token'
|
|
||||||
$Secret_path = $Tokenfolderpath + '\Egnyte Secret.token'
|
|
||||||
|
|
||||||
|
|
||||||
$client_id = get-content -Path $key_path | ConvertTo-SecureString | ConvertFrom-SecureString -AsPlainText
|
|
||||||
$client_secret = get-content -Path $Secret_path | ConvertTo-SecureString | ConvertFrom-SecureString -AsPlainText
|
|
||||||
if (!($EG_User)) {
|
|
||||||
$EG_User = read-host -Prompt "Enter your Egnyte (non-sso) username. The API will impersonate this user:"
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!($EG_Password)) {
|
|
||||||
$EG_Password = read-host -Prompt "Enter your Egnyte (non-sso) Password" -MaskInput
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$eg_grant_type = 'grant_type=password'
|
|
||||||
$EG_Scopes = 'Egnyte.permission Egnyte.filesystem'
|
|
||||||
|
|
||||||
$eg_auth_token = "client_id=$client_id&client_secret=$client_secret&username=$EG_User&password=$EG_Password&$eg_grant_type&scope=$eg_scopes" #| ConvertTo-SecureString -AsPlainText
|
|
||||||
|
|
||||||
$eg_header = @{
|
|
||||||
'Content-Type' = 'application/x-www-form-urlencoded'
|
|
||||||
'Connection' = 'close'
|
|
||||||
'grant_type' = 'password'
|
|
||||||
}
|
|
||||||
|
|
||||||
# Send actual request
|
|
||||||
$eg_auth_response = Invoke-WebRequest -Uri $OAuthPath -HttpVersion 1.1 -Method Post -body $eg_auth_token -Headers $eg_header
|
|
||||||
|
|
||||||
$eg_bearer_token = ($eg_auth_response.Content | ConvertFrom-Json).access_token
|
|
||||||
|
|
||||||
#Save Bearer Token to file for furture use
|
|
||||||
$TokenPath = $Tokenfolderpath + '\' + $env:COMPUTERNAME + '-' + $env:USERNAME + ' Bearer.token'
|
|
||||||
$eg_bearer_token | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Set-Content -Path $TokenPath
|
|
@ -1,26 +0,0 @@
|
|||||||
$token1 = Get-content -Path .\bearer.token
|
|
||||||
$client_secret = 'MAhCqnVAUUq7RvR73wMd5FB9dUP3hhfwGCB7jrXcG8g9gzCQ3a'
|
|
||||||
$token = 'token=' + $token1 + '&client_secret=' + $client_secret
|
|
||||||
|
|
||||||
$BasePath = 'https://mpe.egnyte.com'
|
|
||||||
$RevokePath = $BasePath + '/pubapi/v1/tokens/revoke'
|
|
||||||
|
|
||||||
$eg_header = @{
|
|
||||||
'Content-Type' = 'application/x-www-form-urlencoded'
|
|
||||||
'Connection' = 'close'
|
|
||||||
'Authorization' = 'Bearer ' + $token1
|
|
||||||
}
|
|
||||||
|
|
||||||
# $body = @{
|
|
||||||
# $
|
|
||||||
|
|
||||||
|
|
||||||
# }
|
|
||||||
|
|
||||||
$Revoke_Response = Invoke-WebRequest -Uri $RevokePath -HttpVersion 1.1 -Method Post -body $token -Headers $eg_header
|
|
||||||
|
|
||||||
if ($Revoke_Response.StatusCode -eq 200) {
|
|
||||||
write-output "token revoked successfully, deleting"
|
|
||||||
remove-item .\bearer.token
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user