Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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:

  1. Request username and password:

    Code Block
    languagepowershell
    $user = Read-Host -Prompt 'User name'
    $pass = Read-Host -Prompt 'password' -AsSecureString


  2. Convert secureString to plain text:

    Code Block
    languagepowershell
    $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pass)
    $UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)


  3. Generate request Headers with Authentication: Basic:

    Code Block
    languagepowershell
    $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"


  4. Make the POST request to /auth/request-token

    Code Block
    languagepowershell
    Invoke-RestMethod -uri "https://vss-api.eis.utoronto.ca/auth/request-token" -Headers $headers -method POST


  5. After populating $TK, it can be used for any of the API calls by:

    Code Block
    languagepowershell
    $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}


Filter by label (Content by label)
showLabelsfalse
max5
spacesAPI
sortmodified
showSpacefalse

...

reversetrue
typepage
cqllabel in ( "powershell" , "authentication" , "ps" ) and type = "page" and space = "API"
labelspowershell ps authentication
Page Properties
hiddentrue


Related issues