functions/azure/Get-RequestHeaderAuthorization.ps1

function Get-RequestHeaderAuthorization {
    param(
        [Parameter(ParameterSetName = 'Scope')]
        [string]$Scope,
        [Parameter(ParameterSetName = 'RequestUri')]
        [uri]$RequestUri
    )
    
    if ($Scope) {
        $scope = $Scope
    }
    elseif ($RequestUri) {
        $scope = Get-ScopeFromEndpoint -Endpoint $RequestUri
    }
    else {
        Write-Error 'Unable to determine authentication scope!'
        return $false
    }

    if ($null -eq $BcAdminSession.AzureAccessTokens -or $null -eq $BcAdminSession.AzureAccessTokens[$scope]) {
        Write-Error "Not authenticated for scope $($scope)!"
        return $false
    }

    return $BcAdminSession.AzureAccessTokens[$scope].header_authorization
}