Functions/Set-SkyTapAuth.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
39
40
41
42
43
44
45
46
47
48
<#
 
.SYNOPSIS
Prepares SkyTap Username & API Key for Authentication
 
.DESCRIPTION
Converts SkyTap Username:APIKey to Base64 encoded format for
authenticating to the SkyTap API using Basic Authentication.
 
.PARAMETER Username
SkyTap Username (i.e. address@email.com)
 
.PARAMETER APIKey
SkyTap API Key (https://help.skytap.com/kb-find-api-token.html?Highlight=api%20token)
 
.EXAMPLE
$authSkyTap = Set-SkyTapAuth -Username Joseph.Garcia@cyberark.com -Password 1caf650714f5acec93a490ees9c
 
.EXAMPLE
[xml]$config = Get-Content -Path "settings.xml"
$authSkyTap = Set-SkyTapAuth -Username ${config.Settings.SkyTap.Authentication.SkyTapAPIUser} `
    -Password ${config.Settings.SkyTap.Authentication.SkyTapAPIPass}
 
.OUTPUTS
Returns Base64-encoded Username:APIKey string.
 
#>


function Set-SkyTapAuth {

    [CmdletBinding()]
    param (

        [Parameter(Mandatory=$true)]
        [string]$Username,

        [Parameter(Mandatory=$true)]
        [string]$APIKey

    )

    # Converts Username:Password to Base64-encoded string
    $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $Username,$APIKey)))

    # Returns Base64-encoded string
    $base64AuthInfo

} # end Function: Set-SkyTapAuth