Self-Service PowerShell Universal App Tokens

Here’s a small dashboard to allow users to generate their own app tokens. The JWT Issuer, Audience and Signing key should match what is in your appsettings.json. It also lets you set your own expiry because we currently don’t let you do that in UI.

New-UDDashboard -Title "App Token" -Content {
    Connect-UAServer -ComputerName 'http://localhost:5000' -AppToken '<admin app token here>'

    New-UDDynamic -Id 'token' -Content {
        if ($Session:Token)
        {
            New-UDCard -Title 'App Token' -Content {
                New-UDTypography -Text "AppToken valid until: $Session:ExpiryDate" -Variant h4
                
                New-UDPaper -Content {
                    New-UDHTML -Markup "<p style='word-break: break-all'>$Session:token</p>"
                }
            }

        }
    }

    New-UDButton -Text 'Generate' -OnClick {
        $Session:ExpiryDate = (Get-Date).AddDays(1)
        $Session:Token = (Grant-UAAppToken -IdentityName $User -Role 'Operator' -Expiry $Session:ExpiryDate -SigningKey 'PleaseUseYourOwnSigningKeyHere' -Issuer 'IronmanSoftware' -Audience 'PowerShellUniversal').Token
        Sync-UDElement -Id 'token'
    }
}

3 Likes