Private/Get-AzdoAuthHeaders.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Function Get-AzdoAuthHeaders {
    [cmdletbinding()]
    Param(
    
        [Parameter(Mandatory = $True)]
        [ValidateNotNullOrEmpty()]
        [string]
        $Organization,
            
        [Parameter(Mandatory = $True)]
        [ValidateNotNullOrEmpty()]
        [string]
        $PersonalAccessToken,
    
        [Parameter(Mandatory = $False)]
        [ValidateSet(
            "5.1",
            "6.0-preview"
        )]
        [string]
        $ApiVersion = "6.0-preview"
    
    )
    
    $BaseUri = "https://dev.azure.com/{0}" -f $Organization
    $AuthBase64 = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(" :$PersonalAccessToken"))
    $Headers = @{
        Authorization  = "Basic $AuthBase64"
        "Content-Type" = "application/json; charset=utf-8"
        Accept         = "application/json; api-version=$ApiVersion"
    }
    Return [pscustomobject]@{
        BaseUri = $BaseUri
        Headers = $Headers
    
    }
    
}