Private/Get-TokenExpiry.ps1

#Requires -Version 7
function Get-TokenExpiry {
    <#
    .SYNOPSIS
        Calculates and returns the expiry date/time of an access token.
    .DESCRIPTION
        Takes the expires in time for an auth token and returns a PowerShell date/time object containing the expiry date/time of the token.
    .OUTPUTS
        A powershell date/time object representing the token expiry.
    #>

    [CmdletBinding()]
    [OutputType([DateTime])]
    param (
        # Timestamp value for token expiry. e.g 3600
        [Parameter(
            Mandatory = $True
        )]
        [Int]$ExpiresIn
    )
    $Now = Get-Date
    $TimeZone = Get-TimeZone
    $UTCTime = $Now.AddSeconds($ExpiresIn)
    $UTCOffset = $TimeZone.GetUtcOffset($(Get-Date)).TotalMinutes
    $ExpiryDateTime = $UTCTime.AddMinutes($UTCOffset)
    Write-Verbose "Calcuated token expiry as $($ExpiryDateTime.ToString())"
    Return $ExpiryDateTime
}