我正在尝试使用将令牌字符串转换为jwt令牌JwtSecurityTokenHandler。但是说那是错误的
IDX12709:CanReadToken()返回false。JWT的格式不正确:“ [[PII隐藏]”。\ n令牌必须采用JWS或JWE Compact序列化格式。(JWS):“ EncodedHeader.EndcodedPayload.EncodedSignature”。(JWE):“ EncodedProtectedHeader.EncodedEncryptedKey.EncodedInitializationVector.EncodedCiphertext.EncodedAuthenticationTag”。
我该如何解决这个问题?
这是我的令牌
。
var tokenHandler = new JwtSecurityTokenHandler();
var jwtToken = tokenHandler.ReadToken(token) as JwtSecurityToken;
Run Code Online (Sandbox Code Playgroud)
调用Web API
using (HttpClient client = new HttpClient())
{
string path = "UserMaintenance/ValidateUserId?userid=" + txtUsername.Text.Trim().ToString();
client.BaseAddress = new Uri(GlobalData.BaseUri);
client.DefaultRequestHeaders.Add("Authorization", "Bearer" + GlobalData.Token);
HttpResponseMessage response = client.GetAsync(path).Result;
if (response.IsSuccessStatusCode)
{
var value = response.Content.ReadAsStringAsync().Result;
isValid = JsonConvert.DeserializeObject<bool>(value);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的GetPrincipal方法
public static ClaimsPrincipal GetPrincipal(string token)
{
try
{
var symmetricKey = Convert.FromBase64String(Secret);
var validationParameters = new TokenValidationParameters() …Run Code Online (Sandbox Code Playgroud)