Public/ps1/UblionToken.ps1

    <#
    .SYNOPSIS
    Create bearer token
 
    .DESCRIPTION
    Create a bearer token based on the login credentials
 
    .EXAMPLE
    An example
 
    .NOTES
    General notes
    #>
#
    function Get-LeftConnectToken{
        param ([switch]$force)

        if ($force) {
            remove-variable Token -Scope Global
        }

        $global:Token = Get-ConfigurationValue -name ConnectToken -secure


        if (-not [string]::IsNullOrEmpty($global:Token) ){
            $global:Token
        } else {
            write-host -backgroundcolor green new token required
            $data = Get-LeftConnectBaseConfiguration
            $loginBody = "{""userNameOrEmailAddress"": """+$data.user+""",""password"": """+$data.pass+"""}"
            $connectionApiString = "api/TokenAuth/Authenticate"

            $authorizationUrl = (Get-LeftConnectUrlHost) + $connectionApiString
            Log("Trying to connect to $authorizationUrl")
            $login = Invoke-RestMethod  $authorizationUrl -Method Post -Body $loginBody -ContentType "application/json" 

            $global:Token = $login.result.accessToken
            $global:Token

            Set-ConfigurationValue -name ConnectToken -value $global:Token -secure
        }
    }

    

Export-ModuleMember -function  Get-LeftConnectToken