JWT 401 Problem | Community
Skip to main content

JWT 401 Problem

  • August 2, 2022
  • 3 replies
  • 0 views

Marcin14

Hi,

I've created own JWT endpoint for Zendesk Url: "https://sagra.zendesk.com" but unfortunately I'm still getting 401 response when using iOS SDK.

Of course I've read docs and I've included all required fields (name, email, iat, jti).

Is there any possibility to check what am I doing wrong?

3 replies

Greg29
  • August 2, 2022

Hi Marcin! I checked the logs for your subdomain and it looks like the payload that you're sending is not correct. Could you please share the code snippet for the generation of the token so that we can see what might be going wrong? I also recommend using jwt.io to check that generated tokens in testing are indeed creating the correct payload.


Marcin14
  • Author
  • August 3, 2022

Hi, Thanks for your reply. Here is the snippet of JWT creation code (.NET/C#):

var name = "m******";
var email = "m*******@****.com";
var securityKey = _configuration["SecurityKey"];

var claims = new[] {
                    new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                    new Claim(JwtRegisteredClaimNames.Name, name),
                    new Claim(JwtRegisteredClaimNames.Iat, DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString(), ClaimValueTypes.Integer64),
                    new Claim(JwtRegisteredClaimNames.Email, email),
                };

var handler = new JwtSecurityTokenHandler();

var token = new JwtSecurityToken
            (
                claims: claims,
                signingCredentials: new SigningCredentials(new SymmetricSecurityKey(System.Text.Encoding.ASCII.GetBytes(securityKey)), SecurityAlgorithms.HmacSha256)
            );

return base.Content(handler.WriteToken(token), "application/jwt");

Marcin14
  • Author
  • August 16, 2022

Is there any way to check myself what am I doing wrong?