Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating symmetric key to match the JWT generated by .Net core #200

Open
ramkithepower opened this issue Sep 29, 2022 · 1 comment
Open

Comments

@ramkithepower
Copy link

The third party API I am working with is asking me to generate the JWT on client side. I understand that they use the following code to verify JWT.


using System;
using System.Text;
using Microsoft.IdentityModel.Tokens;
using Microsoft.AspNetCore.Builder;

// The key length needs to be of sufficient length, or otherwise an error will occur.
var tokenSecretKey = Encoding.UTF8.GetBytes(Configuration["TokenSecretKey"]);

var tokenValidationParameters = new TokenValidationParameters
{
    // Token signature will be verified using a private key.
    ValidateIssuerSigningKey = true,
    IssuerSigningKey = new SymmetricSecurityKey(tokenSecretKey),
    ValidateIssuer = false,
    ValidateAudience = false
};

services.AddAuthentication(options =>
        {
            options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
            options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
        }).AddJwtBearer(options => { options.RequireHttpsMetaData = false;
options.SaveToken = true; 
 options.TokenValidationParameters = tokenValidationParameters; 
});

In the client side the token generation I have created is as follows using Jose JWT.
return Jose.JWT.Encode(claims, byteArrayOfKey, Jose.JwsAlgorithm.HS256);

but the validation is failing with 401 on server side. Is there anything I can do match the server side.

@dvsekhvalnov
Copy link
Owner

Hey @ramkithepower , that's hard to guess without additional details.

May be key mismatch, maybe they don't like something in your claims (aud, iss, dates), make be clock skew between client and server.

Try to get some logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants