NDOT
NDOT
Explore posts from servers
CC#
Created by NDOT on 4/27/2024 in #help
✅ Configurations say that appsettings is returning null
anything that i'm doing extremely wrong ?
7 replies
CC#
Created by NDOT on 4/27/2024 in #help
✅ Configurations say that appsettings is returning null
it returns null from it
7 replies
CC#
Created by NDOT on 4/27/2024 in #help
✅ Configurations say that appsettings is returning null
and that's how i'm trying to access it :
if (int.TryParse(_configuration["ClientId"], out clientId))
if (int.TryParse(_configuration["ClientId"], out clientId))
7 replies
CC#
Created by NDOT on 4/27/2024 in #help
✅ Configurations say that appsettings is returning null
that's my appsettings :
{
"ClientId": 0,
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
{
"ClientId": 0,
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
7 replies
CC#
Created by Scottek utek on 3/19/2023 in #help
✅ jwt authentication always returns 401
42 replies
CC#
Created by Scottek utek on 3/19/2023 in #help
✅ jwt authentication always returns 401
builder.Services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.Authority = domain;
options.Audience =builder.Configuration["Auth0:Audience"];
// If the access token does not have a `sub` claim, `User.Identity.Name` will be `null`. Map it to a different claim by setting the NameClaimType below.
options.TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = ClaimTypes.NameIdentifier
};
});
builder.Services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.Authority = domain;
options.Audience =builder.Configuration["Auth0:Audience"];
// If the access token does not have a `sub` claim, `User.Identity.Name` will be `null`. Map it to a different claim by setting the NameClaimType below.
options.TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = ClaimTypes.NameIdentifier
};
});
i did put both, but i didn't find about how to add the middleware in .NET 6 without using the Startup.cs
42 replies
CC#
Created by Scottek utek on 3/19/2023 in #help
✅ jwt authentication always returns 401
.net 6 doesn't have one, it's the Program.cs, but works almost the same way i think
42 replies
CC#
Created by Scottek utek on 3/19/2023 in #help
✅ jwt authentication always returns 401
nop
42 replies
CC#
Created by Scottek utek on 3/19/2023 in #help
✅ jwt authentication always returns 401
where can i insert then?
42 replies
CC#
Created by Scottek utek on 3/19/2023 in #help
✅ jwt authentication always returns 401
(and in the tutorial did work so i thought it would be something wrong in my code)
42 replies
CC#
Created by Scottek utek on 3/19/2023 in #help
✅ jwt authentication always returns 401
i was just following a tutorial
42 replies
CC#
Created by Scottek utek on 3/19/2023 in #help
✅ jwt authentication always returns 401
hmm... no ?
42 replies
CC#
Created by Scottek utek on 3/19/2023 in #help
✅ jwt authentication always returns 401
my whole method that creates the JWT is that>
List<Claim> claims = new List<Claim>
{
new Claim(ClaimTypes.Name, user.Username)
};
var key = new SymmetricSecurityKey(System.Text.Encoding.UTF8.GetBytes("absca4234srhaowurha3uo"));

var cred = new SigningCredentials(key, SecurityAlgorithms.HmacSha512Signature);

var token = new JwtSecurityToken
(
claims: claims,
expires: DateTime.Now.AddSeconds(1800),
signingCredentials : cred
);

var jwt = new JwtSecurityTokenHandler().WriteToken(token);
return jwt;
List<Claim> claims = new List<Claim>
{
new Claim(ClaimTypes.Name, user.Username)
};
var key = new SymmetricSecurityKey(System.Text.Encoding.UTF8.GetBytes("absca4234srhaowurha3uo"));

var cred = new SigningCredentials(key, SecurityAlgorithms.HmacSha512Signature);

var token = new JwtSecurityToken
(
claims: claims,
expires: DateTime.Now.AddSeconds(1800),
signingCredentials : cred
);

var jwt = new JwtSecurityTokenHandler().WriteToken(token);
return jwt;
42 replies
CC#
Created by Scottek utek on 3/19/2023 in #help
✅ jwt authentication always returns 401
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
42 replies
CC#
Created by Scottek utek on 3/19/2023 in #help
✅ jwt authentication always returns 401
not fast api, just a common webapi
42 replies
CC#
Created by Scottek utek on 3/19/2023 in #help
✅ jwt authentication always returns 401
btw i'm using .NET 6
42 replies
CC#
Created by Scottek utek on 3/19/2023 in #help
✅ jwt authentication always returns 401
i mean, i did just make a simple, Login endpoint, that creates a JWT that allows you to access the other endpoints
42 replies
CC#
Created by Scottek utek on 3/19/2023 in #help
✅ jwt authentication always returns 401
wdym?
42 replies
CC#
Created by Scottek utek on 3/19/2023 in #help
✅ jwt authentication always returns 401
var key = new SymmetricSecurityKey(System.Text.Encoding.UTF8.GetBytes(_configuration.GetSection("Jwt:Key").Value));

var cred = new SigningCredentials(key, SecurityAlgorithms.HmacSha512Signature);

var token = new JwtSecurityToken
(
claims: claims,
expires: DateTime.Now.AddSeconds(1800), signingCredentials : cred
);
var jwt = new JwtSecurityTokenHandler().WriteToken(token);
return jwt;
var key = new SymmetricSecurityKey(System.Text.Encoding.UTF8.GetBytes(_configuration.GetSection("Jwt:Key").Value));

var cred = new SigningCredentials(key, SecurityAlgorithms.HmacSha512Signature);

var token = new JwtSecurityToken
(
claims: claims,
expires: DateTime.Now.AddSeconds(1800), signingCredentials : cred
);
var jwt = new JwtSecurityTokenHandler().WriteToken(token);
return jwt;
that's basically the function that creates my JWT's
42 replies
CC#
Created by Scottek utek on 3/19/2023 in #help
✅ jwt authentication always returns 401
mine ones
42 replies