functions/Get-PSBlueSkyAccessToken.ps1

Function Get-BskyAccessToken {
    [cmdletbinding()]
    [OutputType([System.String])]

    Param (
        [Parameter(Mandatory, HelpMessage = 'A PSCredential with your Bluesky username and password')]
        [PSCredential]$Credential
    )

    if ($Null -eq $script:BSkySession) {
        Write-Verbose "Creating a new Bluesky session for $($Credential.UserName)"
         _CreateSession -Credential $Credential
    }
    elseif (-Not ($script:BSkySession.active)) {
        Write-Verbose "Refreshing the Bluesky session for $($Credential.UserName)"
        _RefreshSession -RefreshToken $script:BSkySession.refreshJwt
    }
    else {
        Write-Verbose "Using the existing Bluesky session for $($Credential.UserName)"
        $script:BSkySession.accessJwt
    }

}