-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathAccessToken.regex.ps1
39 lines (33 loc) · 933 Bytes
/
AccessToken.regex.ps1
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
<#
.Synopsis
Matches Access Tokens
.Description
Matches Access Tokens.
Access Tokens are single-line base64 strings that have more than -MinimumLength characters (default 40)
#>
param(
# The Minimum Length of an Access Token. By default, 40 characters
[int]
$MinimumLength = 40,
# The Maximum Length of an Access Token. By default, 1kb characters
[int]
$MaximumLength = 1kb,
# If set, will look for a hexadecimal access token.
# By default, will match Base64 access tokens
[switch]
$Hex,
# If set, will allow the token to be a JSON Web Token.
# These are similar to Base64 tokens, but may contain periods (and will tend to be longer)
[Alias('JSONWebToken')]
[switch]
$JWT
)
if ($Hex) {
"(?<AccessToken>[0-9a-f]{$MinimumLength,$MaximumLength})"
}
elseif ($JWT) {
"(?<AccessToken>[0-9a-z/=\+\.]{$MinimumLength,$MaximumLength})"
}
else {
"(?<AccessToken>[0-9a-z/=\+]{$MinimumLength,$MaximumLength})"
}