优化jwt首次无数据的异常。
This commit is contained in:
@@ -103,15 +103,23 @@ namespace CoreCms.Net.Auth
|
|||||||
{
|
{
|
||||||
OnMessageReceived = context =>
|
OnMessageReceived = context =>
|
||||||
{
|
{
|
||||||
var token = context.Request.Headers["Authorization"].ObjectToString().Replace("Bearer ", "");
|
try
|
||||||
if (string.IsNullOrEmpty(token))
|
|
||||||
{
|
{
|
||||||
context.Response.Headers.Append("Token-Error-Token", "authorization decryption failure!");
|
var token = context.Request.Headers["Authorization"].ObjectToString().Replace("Bearer ", "");
|
||||||
}
|
if (!string.IsNullOrEmpty(token.Trim()))
|
||||||
else
|
|
||||||
{
|
{
|
||||||
context.Token = EncryptProvider.AESDecrypt(token, AppSettingsConstVars.JwtConfigSecretKey);
|
context.Token = EncryptProvider.AESDecrypt(token, AppSettingsConstVars.JwtConfigSecretKey);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.Response.Headers.Append("Token-Error-Token", "authorization decryption failure!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
context.Response.Headers.Append("Token-Error-Token", "authorization decryption failure ex!");
|
||||||
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
},
|
},
|
||||||
OnChallenge = context =>
|
OnChallenge = context =>
|
||||||
@@ -122,18 +130,14 @@ namespace CoreCms.Net.Auth
|
|||||||
OnAuthenticationFailed = context =>
|
OnAuthenticationFailed = context =>
|
||||||
{
|
{
|
||||||
var token = context.Request.Headers["Authorization"].ObjectToString().Replace("Bearer ", "");
|
var token = context.Request.Headers["Authorization"].ObjectToString().Replace("Bearer ", "");
|
||||||
if (string.IsNullOrEmpty(token))
|
if (!string.IsNullOrEmpty(token.Trim()))
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
context.Response.Headers.Append("Token-Error-Token", "token is wrong!");
|
|
||||||
}
|
|
||||||
|
|
||||||
//进行aes解密
|
//进行aes解密
|
||||||
var decodeToken = EncryptProvider.AESDecrypt(token, AppSettingsConstVars.JwtConfigSecretKey);
|
var decodeToken = EncryptProvider.AESDecrypt(token, AppSettingsConstVars.JwtConfigSecretKey);
|
||||||
if (string.IsNullOrEmpty(decodeToken))
|
if (!string.IsNullOrEmpty(decodeToken))
|
||||||
{
|
{
|
||||||
context.Response.Headers.Append("Token-Error-Token", "token decryption failure!");
|
|
||||||
}
|
|
||||||
|
|
||||||
var jwtToken = (new JwtSecurityTokenHandler()).ReadJwtToken(decodeToken);
|
var jwtToken = (new JwtSecurityTokenHandler()).ReadJwtToken(decodeToken);
|
||||||
|
|
||||||
if (jwtToken.Issuer != issuer)
|
if (jwtToken.Issuer != issuer)
|
||||||
@@ -151,6 +155,23 @@ namespace CoreCms.Net.Auth
|
|||||||
{
|
{
|
||||||
context.Response.Headers.Append("Token-Expired", "true");
|
context.Response.Headers.Append("Token-Expired", "true");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.Response.Headers.Append("Token-Error-Token", "token decryption failure!");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
context.Response.Headers.Append("Token-Error-Token", "token decryption failure ex!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.Response.Headers.Append("Token-Error-Token", "token is wrong!");
|
||||||
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -233,15 +254,23 @@ namespace CoreCms.Net.Auth
|
|||||||
{
|
{
|
||||||
OnMessageReceived = context =>
|
OnMessageReceived = context =>
|
||||||
{
|
{
|
||||||
var token = context.Request.Headers["Authorization"].ObjectToString().Replace("Bearer ", "");
|
try
|
||||||
if (string.IsNullOrEmpty(token))
|
|
||||||
{
|
{
|
||||||
context.Response.Headers.Append("Token-Error-Token", "authorization decryption failure!");
|
var token = context.Request.Headers["Authorization"].ObjectToString().Replace("Bearer ", "");
|
||||||
}
|
if (!string.IsNullOrEmpty(token.Trim()))
|
||||||
else
|
|
||||||
{
|
{
|
||||||
context.Token = EncryptProvider.AESDecrypt(token, AppSettingsConstVars.JwtConfigSecretKey);
|
context.Token = EncryptProvider.AESDecrypt(token, AppSettingsConstVars.JwtConfigSecretKey);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.Response.Headers.Append("Token-Error-Token", "authorization decryption failure!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
context.Response.Headers.Append("Token-Error-Token", "authorization decryption failure ex!");
|
||||||
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
},
|
},
|
||||||
OnChallenge = context =>
|
OnChallenge = context =>
|
||||||
@@ -252,18 +281,14 @@ namespace CoreCms.Net.Auth
|
|||||||
OnAuthenticationFailed = context =>
|
OnAuthenticationFailed = context =>
|
||||||
{
|
{
|
||||||
var token = context.Request.Headers["Authorization"].ObjectToString().Replace("Bearer ", "");
|
var token = context.Request.Headers["Authorization"].ObjectToString().Replace("Bearer ", "");
|
||||||
if (string.IsNullOrEmpty(token))
|
if (!string.IsNullOrEmpty(token.Trim()))
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
context.Response.Headers.Append("Token-Error-Token", "token is wrong!");
|
|
||||||
}
|
|
||||||
|
|
||||||
//进行aes解密
|
//进行aes解密
|
||||||
var decodeToken = EncryptProvider.AESDecrypt(token, AppSettingsConstVars.JwtConfigSecretKey);
|
var decodeToken = EncryptProvider.AESDecrypt(token, AppSettingsConstVars.JwtConfigSecretKey);
|
||||||
if (string.IsNullOrEmpty(decodeToken))
|
if (!string.IsNullOrEmpty(decodeToken))
|
||||||
{
|
{
|
||||||
context.Response.Headers.Append("Token-Error-Token", "token decryption failure!");
|
|
||||||
}
|
|
||||||
|
|
||||||
var jwtToken = (new JwtSecurityTokenHandler()).ReadJwtToken(decodeToken);
|
var jwtToken = (new JwtSecurityTokenHandler()).ReadJwtToken(decodeToken);
|
||||||
|
|
||||||
if (jwtToken.Issuer != issuer)
|
if (jwtToken.Issuer != issuer)
|
||||||
@@ -281,6 +306,23 @@ namespace CoreCms.Net.Auth
|
|||||||
{
|
{
|
||||||
context.Response.Headers.Append("Token-Expired", "true");
|
context.Response.Headers.Append("Token-Expired", "true");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.Response.Headers.Append("Token-Error-Token", "token decryption failure!");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
context.Response.Headers.Append("Token-Error-Token", "token decryption failure ex!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.Response.Headers.Append("Token-Error-Token", "token is wrong!");
|
||||||
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user