Public/Get-SfHeaders.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
<#
    .SYNOPSIS
    Authenticates with Salesforce and returns bearer token header for future calls

    .DESCRIPTION
    Authenticates with Salesforce and returns bearer token header for future calls

    .INPUTS
    None. You cannot pipe objects to Get-SfDevices.

    .OUTPUTS
    A Hashtable with the "Authorization" key and the bearer token.

    .EXAMPLE
    PS> Set-FileConfig; (get-sfheaders)['Authorization']
    Bearer 00D4J0000001pvr!ARkAQLxHMmfUHYvbKYmRveGi.SayYuxZ4vL18Ra9Sk0eBh1hciD3yuItxmdLoNgB0R1v8xQE5cl.FnnjUxL1L_afg7FgmLnN

    .LINK
    Set-FileConfig

    .NOTES
    Assumes config is initialized for org access.
#>

function Get-SfHeaders {
    param([String]$access_token)
    $response = Invoke-SfAuthenticate
    $access_token = $response.access_token
    @{ "Authorization" = "Bearer $($access_token)"}
}