From 492b7b73635c3f9f9c89f6e02a44b6014c2c1856 Mon Sep 17 00:00:00 2001 From: eeckert Date: Wed, 6 Dec 2023 07:56:44 -0700 Subject: [PATCH] moving to main PS repo --- API Tokens/Get_Bearer_Token.ps1 | 52 --------------------------------- API Tokens/Revoke-OldToken.ps1 | 26 ----------------- 2 files changed, 78 deletions(-) delete mode 100644 API Tokens/Get_Bearer_Token.ps1 delete mode 100644 API Tokens/Revoke-OldToken.ps1 diff --git a/API Tokens/Get_Bearer_Token.ps1 b/API Tokens/Get_Bearer_Token.ps1 deleted file mode 100644 index fa78725..0000000 --- a/API Tokens/Get_Bearer_Token.ps1 +++ /dev/null @@ -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 \ No newline at end of file diff --git a/API Tokens/Revoke-OldToken.ps1 b/API Tokens/Revoke-OldToken.ps1 deleted file mode 100644 index da43f0b..0000000 --- a/API Tokens/Revoke-OldToken.ps1 +++ /dev/null @@ -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 - -}