Gord Russell wrote wrote auth.ps1 (thanks!) to generate an access token using Microsoft PowerShell. It implements the Invoke-RestMethod to send an HTTPS POST request to the VSS RESTful web service, then PowerShell deserializes the JavaScript Object Notation (JSON) content into objects.
...
The following steps explain how auth.ps1 works:
Request username and password:
Code Block language powershell $user = Read-Host -Prompt 'User name' $pass = Read-Host -Prompt 'password' -AsSecureString
Convert secureString to plain text:
Code Block language powershell $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pass) $UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
Generate request Headers with Authentication: Basic:
Code Block language powershell $pair = $user + ":" + $UnsecurePassword # Encode the string to the RFC2045-MIME variant of Base64, except not limited to 76 char/line. $bytes = [System.Text.Encoding]::ASCII.GetBytes($pair) $base64 = [System.Convert]::ToBase64String($bytes) # Create the Auth value as the method, a space, and then the encoded pair Method Base64String $basicAuthValue = "Basic $base64"
Make the POST request to /auth/request-token
Code Block language powershell Invoke-RestMethod -uri "https://vss-api.eis.utoronto.ca/auth/request-token" -Headers $headers -method POST
After populating $TK, it can be used for any of the API calls by:
Code Block language powershell $authVal = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($tk.token)) Invoke-RestMethod -uri "https://vss-ws.eis.utoronto.ca/v2/vm" -Headers @{"AUTHORIZATION"=$authVal}
Related articles
Filter by label (Content by label) | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
...
|
Page Properties | ||
---|---|---|
| ||
|