-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExportJwt.ps1
More file actions
50 lines (41 loc) · 1.79 KB
/
ExportJwt.ps1
File metadata and controls
50 lines (41 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env pwsh
# Test script that generates a mock JWT token with timestamp
# In production, this would fetch a real token from your auth service
#
# To run this script without loading PowerShell profile:
# pwsh -NoProfile -NonInteractive -ExecutionPolicy Bypass -File .\ExportJwt.ps1
#
# Or as a one-liner command:
# pwsh -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "& { .\ExportJwt.ps1 }"
# Ensure no extra output
$ErrorActionPreference = "SilentlyContinue"
# Get current timestamp
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
# For Unix timestamp, handle different PowerShell versions
if ($PSVersionTable.PSVersion.Major -ge 7) {
# PowerShell Core/7+ has built-in Unix time support
$unixTime = [int](Get-Date -UFormat %s)
} else {
# Windows PowerShell 5.1 needs manual calculation
$unixTime = [int]([DateTimeOffset]::UtcNow.ToUnixTimeSeconds())
}
# Create a simple mock JWT-like token with timestamp embedded
# Real JWT would have proper header.payload.signature structure
$header = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes('{"alg":"HS256","typ":"JWT"}'))
# Create payload with proper JSON
$payloadJson = @{
sub = "test-user"
iat = $unixTime
exp = $unixTime + 900
timestamp = $timestamp
} | ConvertTo-Json -Compress
$payload = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($payloadJson))
# Include seconds in signature so we can see it change with each refresh
$signature = "test-sig-" + (Get-Date -Format "HHmmss")
# Clean up base64 padding if needed (standard JWT doesn't use padding)
$header = $header.TrimEnd('=')
$payload = $payload.TrimEnd('=')
# Output ONLY the token to stdout - nothing else
# Use Write-Host to ensure it goes to stdout, not the success stream
$token = "$header.$payload.$signature"
Write-Host $token