Skip to content

Commit

Permalink
1.4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
NickolajA committed Mar 7, 2024
1 parent 5b8c605 commit 21b0c09
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
30 changes: 18 additions & 12 deletions Public/Test-AccessToken.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,38 @@ function Test-AccessToken {
Author: Nickolaj Andersen
Contact: @NickolajA
Created: 2021-04-08
Updated: 2023-09-04
Updated: 2024-03-07
Version history:
1.0.0 - (2021-04-08) Script created
1.0.1 - (2023-09-04) Updated to use TotalMinutes instead of Minutes property, which would cause for inaccurate results
1.0.2 - (2024-03-07) Invocation of function when access token is null will now return false
#>
param(
[parameter(Mandatory = $false, HelpMessage = "Specify the renewal threshold for access token age in minutes.")]
[ValidateNotNullOrEmpty()]
[int]$RenewalThresholdMinutes = 10
)
Process {
# Determine the current time in UTC
$UTCDateTime = (Get-Date).ToUniversalTime()

# Determine the token expiration count as minutes
$TokenExpireMinutes = [System.Math]::Round(([datetime]$Global:AccessToken.ExpiresOn.ToUniversalTime().UtcDateTime - $UTCDateTime).TotalMinutes)

# Determine if refresh of access token is required when expiration count is less than or equal to minimum age
if ($TokenExpireMinutes -le $RenewalThresholdMinutes) {
Write-Verbose -Message "Access token refresh is required, current token expires in (minutes): $($TokenExpireMinutes)"
if ($Global:AccessToken -eq $null) {
return $false
}
else {
Write-Verbose -Message "Access token refresh is not required, remaining minutes until expiration: $($TokenExpireMinutes)"
return $true
# Determine the current time in UTC
$UTCDateTime = (Get-Date).ToUniversalTime()

# Determine the token expiration count as minutes
$TokenExpireMinutes = [System.Math]::Round(([datetime]$Global:AccessToken.ExpiresOn.ToUniversalTime().UtcDateTime - $UTCDateTime).TotalMinutes)

# Determine if refresh of access token is required when expiration count is less than or equal to minimum age
if ($TokenExpireMinutes -le $RenewalThresholdMinutes) {
Write-Verbose -Message "Access token refresh is required, current token expires in (minutes): $($TokenExpireMinutes)"
return $false
}
else {
Write-Verbose -Message "Access token refresh is not required, remaining minutes until expiration: $($TokenExpireMinutes)"
return $true
}
}
}
}
2 changes: 2 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- Improved (hopefully) all aspects as to add and remove supersedence and dependencies.
- Improved return object property handling in `Get-IntuneWin32AppAssignment` function to include the same properties independent if using ID or Group parameter set. GroupID and GroupName properties are now also visible in the return object from the function when the ID parameter set is used and an assignment target type matches a group.
- Fixed a typo in the Test-AccessToken inner function of the `New-IntuneWin32AppDependency` function implementation where it was not encapsulating the function execution inside parentheses.
- Merged PR: ValidateRange works not as intended because the values are strings #142
- Fixed mentioned issue with `Test-AccessToken` function mentioned in #138

## 1.4.3
- Updated the New-IntuneWin32AppPackage function to work properly after the latest version of the IntuneWinAppUtil.exe was recently updated.
Expand Down

0 comments on commit 21b0c09

Please sign in to comment.