-
Notifications
You must be signed in to change notification settings - Fork 0
/
redirect.cs
44 lines (38 loc) · 1.44 KB
/
redirect.cs
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
using System;
using Microsoft.IdentityModel.Tokens;
class JwtDecoder
{
static void Main(string[] args)
{
string apiKey = "API_KEY"; // Specify your API key
string phtoken = "your_jwt_token_here"; // Replace with the JWT token you want to decode
int jwtResponse = 0;
string jwtPhone = "";
var tokenHandler = new JwtSecurityTokenHandler();
var validationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(System.Text.Encoding.UTF8.GetBytes(apiKey)),
ValidAlgorithms = new[] { SecurityAlgorithms.HmacSha256 }
};
try
{
SecurityToken validatedToken;
var claimsPrincipal = tokenHandler.ValidateToken(phtoken, validationParameters, out validatedToken);
jwtResponse = 1; // JWT decoded successfully
var countryCode = claimsPrincipal.FindFirst("country_code").Value;
var phoneNo = claimsPrincipal.FindFirst("phone_no").Value;
jwtPhone = countryCode + phoneNo;
}
catch (SecurityTokenExpiredException)
{
jwtResponse = 0; // Invalid JWT
}
catch (SecurityTokenValidationException)
{
jwtResponse = 0; // Invalid JWT
}
Console.WriteLine($"JWT Response: {jwtResponse}");
Console.WriteLine($"JWT Phone: {jwtPhone}");
}
}