Private/Get-SFToken.ps1

function Get-SFToken {
    [CmdletBinding(DefaultParameterSetName = 'Assertion')]
    param (
        [Parameter(Mandatory)]
        [string]$BaseUrl,

        [Parameter(Mandatory)]
        [string]$ClientId,

        [Parameter(Mandatory)]
        [string]$CompanyId,

        [Parameter(Mandatory, ParameterSetName = 'Assertion')]
        [string]$Assertion,

        [Parameter(Mandatory, ParameterSetName = 'ClientCredentials')]
        [string]$ClientSecret,

        [switch]$ForceNew
    )

    $uri = "$BaseUrl/oauth/token"
    $headers = @{ 'Content-Type' = 'application/x-www-form-urlencoded' }
    $body = if ($PSCmdlet.ParameterSetName -eq 'Assertion') {
        @{
            client_id  = $ClientId
            company_id = $CompanyId
            grant_type = 'urn:ietf:params:oauth:grant-type:saml2-bearer'
            assertion  = $Assertion
        }
    }
    else {
        @{
            client_id     = $ClientId
            company_id    = $CompanyId
            grant_type    = 'client_credentials'
            client_secret = $ClientSecret
        }
    }

    if ($ForceNew) {
        $body.new_token = 'true'
    }

    try {
        return Invoke-RestMethod -Method Post -Uri $uri -Headers $headers -Body $body
    }
    catch {
        throw "Failed to obtain SuccessFactors access token from '$uri': $($_.Exception.Message)"
    }
}