|
@@ -2,6 +2,7 @@
|
2
|
2
|
using System.Configuration;
|
3
|
3
|
using System.IdentityModel.Tokens;
|
4
|
4
|
using System.Security.Claims;
|
|
5
|
+using System.ServiceModel.Security.Tokens;
|
5
|
6
|
|
6
|
7
|
namespace iiie.Authentication.Business.JWT
|
7
|
8
|
{
|
|
@@ -47,5 +48,30 @@ namespace iiie.Authentication.Business.JWT
|
47
|
48
|
JwtSecurityTokenHandler jh = new JwtSecurityTokenHandler();
|
48
|
49
|
return jh.WriteToken(jst);
|
49
|
50
|
}
|
|
51
|
+
|
|
52
|
+ public static ClaimsPrincipal ParseToken(string token)
|
|
53
|
+ {
|
|
54
|
+ JwtSecurityTokenHandler tokenHandler = new JwtSecurityTokenHandler
|
|
55
|
+ {
|
|
56
|
+ Configuration = new SecurityTokenHandlerConfiguration()
|
|
57
|
+ {
|
|
58
|
+ MaxClockSkew = new TimeSpan(0, 1, 0)
|
|
59
|
+ }
|
|
60
|
+ };
|
|
61
|
+
|
|
62
|
+ var stringValidator = ConfigurationManager.AppSettings["StringValidator"];
|
|
63
|
+ TokenValidationParameters validationParameters = new TokenValidationParameters()
|
|
64
|
+ {
|
|
65
|
+ RequireSignedTokens = true,
|
|
66
|
+ RequireExpirationTime = true,
|
|
67
|
+ ValidAudience = stringValidator,
|
|
68
|
+ ValidateIssuerSigningKey = true,
|
|
69
|
+ ValidIssuer = "urn:" + stringValidator,
|
|
70
|
+ IssuerSigningToken = new BinarySecretSecurityToken(Convert.FromBase64String(ConfigurationManager.AppSettings["CredentialKey"]))
|
|
71
|
+ };
|
|
72
|
+
|
|
73
|
+ SecurityToken validateToken;
|
|
74
|
+ return tokenHandler.ValidateToken(token, validationParameters, out validateToken);
|
|
75
|
+ }
|
50
|
76
|
}
|
51
|
77
|
}
|