TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ahmed elbarbary
637
1.6k
282k
How to add userid to payload when generate access token usin
Sep 6 2019 11:40 PM
problem
How to add UserId to payload when generate access Token Using JWT asp.net core 2.2 ?
i make function generate access token but i need to modify it to have or load userid on payload and get result as json ?
how to do that if possible ?
I need if string userid paramters have values add it to payload of generate access token .
What I have tried:
public
string
GenerateTokens(
string
userId)
{
var Claims =
new
Claim[]
{
new
Claim(JwtRegisteredClaimNames.Sub,userId)
};
var signingkey =
new
SymmetricSecurityKey(Encoding.UTF8.GetBytes(
"this is secret phrase"
));
var SigningCredntials =
new
SigningCredentials();
var Jwt =
new
JwtSecurityToken();
return
new
JwtSecurityTokenHandler().WriteToken(Jwt);
}
configure service on startup
public
void
ConfigureServices(IServiceCollection services)
{
//=================This Setting Related To generate Access Token Data===============
var signingkey =
new
SymmetricSecurityKey(Encoding.UTF8.GetBytes(
"this is secret phrase"
));
services.AddAuthentication(options => {
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(cfg =>
{
cfg.RequireHttpsMetadata =
false
;
cfg.SaveToken =
false
;
cfg.TokenValidationParameters =
new
Microsoft.IdentityModel.Tokens.TokenValidationParameters()
{
IssuerSigningKey = signingkey,
ValidateAudience =
false
,
ValidateIssuer =
false
,
ValidateLifetime =
false
,
ValidateIssuerSigningKey =
true
};
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
Reply
Answers (
1
)
Are using count login attempt within period by this way is c
Decode base 64 to Image url