Updated: 15 June 2020 – JWTDetails updated to v1.0.2
I’ve just published my first PowerShell Module to the PowerShell Gallery. The JWTDetails PowerShell Module contains the Get-JWTDetails cmdlet that decodes a JWT Access Token and converts it to a PowerShell Object. But wait, there’s more. The reason I created this module is because I always need to know what is the Expiry Time for a JWT Access Token. The returned PowerShell Object from my Get-JWTDetails cmdlet in the JWTDetails Module also includes the expiry date-time in PowerShell DateTime format as ‘expiryDateTime‘. It also includes the ‘timeToExpiry‘ for the Access Token, also in PowerShell DateTime format.
This means you can keep calling the Get-JWTDetails cmdlet with an access token and inspect the ‘expiryDateTime‘ or ‘timeToExpiry‘ fields to determine whether its time for you to go and get a new JWT Access Token.
I’ve published the module to the PowerShell Gallery. Therefore with PowerShell 5.1 and later you can install direct from the PowerShell Gallery (in an Administrative PowerShell Session) using Install-Module.
Install-Module -name JWTDetails
The JWTDetails module contains a single cmdlet ‘Get-JWTDetails‘.
Using Get-JWTDetails is super simple. Import the module and then pass it a JWT Access Token. I’ve been using it with Microsoft Azure and SailPoint IdentityNow JWT Tokens.
Passing the cmdlet a valid SailPoint IdentityNow Access Token as a discrete string, you will be returned the details of the Access Token including the expiry in easy to read format.
Providing the cmdlet with a valid Azure Access Token passed in as a variable you will be returned the details of the Access Token including the expiry in easy to read format.
Let’s put the decoded token into a variable so that we can then easily look at the expiryDateTime and timeToExpiry values. We could then in our scripts define logic about when to refresh our Access Token.
Interested in the PowerShell Module Code, or want to enhance it? Sure thing. I’ve uploaded the module to a Public Repository on Github here.
By publishing this module to the PowerShell Gallery I have a much quicker method of installing the module on each new workstation/environment that I’m in. Hopefully it helps someone else too.
To decode JWT Access Tokens using PowerShell:
A few weeks back the Microsoft AI Tour was in Sydney Australia. There was a…
If you're anything like me you always have PowerShell open, and often both PowerShell and…
Decentralised Identity is a technology I'm passionate about and have written many posts and tools…
Over two years ago I authored a PowerShell Module that enabled the automation of 1Password.…
Buried in my PowerShell Snippets Vol 4 post from 2021 is the PowerShell script and…
Short post on how to recovery from "The Windows Subsystem for Linux instance has terminated"…
This website uses cookies.
View Comments