Salight
Salight
CC#
Created by Salight on 3/12/2025 in #help
Is it good practice to hide dtos in shared if it is not why and what should i do
is this version of using does any harm to runtime
17 replies
CC#
Created by Salight on 3/12/2025 in #help
Is it good practice to hide dtos in shared if it is not why and what should i do
but lets say i am just developing a api
17 replies
CC#
Created by Salight on 3/12/2025 in #help
Is it good practice to hide dtos in shared if it is not why and what should i do
also in mvc
17 replies
CC#
Created by Salight on 3/12/2025 in #help
Is it good practice to hide dtos in shared if it is not why and what should i do
also in dal
17 replies
CC#
Created by Salight on 3/12/2025 in #help
Is it good practice to hide dtos in shared if it is not why and what should i do
i am using in service,service contracts
17 replies
CC#
Created by Salight on 3/12/2025 in #help
Is it good practice to hide dtos in shared if it is not why and what should i do
i didn't understand what do you mean "by need to be shared" if it is possible can you give me a example of that
17 replies
CC#
Created by Salight on 2/25/2025 in #help
✅[Authorize] Doesn't Recognize Default Authentication Scheme?
i just changed the configuration alignment and it solved
4 replies
CC#
Created by Salight on 2/25/2025 in #help
✅[Authorize] Doesn't Recognize Default Authentication Scheme?
Okay i solved
4 replies
CC#
Created by Salight on 2/23/2025 in #help
✅ Onion Architecture Authorization doesn't work
"JwtSettings": {
"validIssuer": "https://localhost:5001",
"validAudience": "https://localhost:5001",
"expires": 5
}
"JwtSettings": {
"validIssuer": "https://localhost:5001",
"validAudience": "https://localhost:5001",
"expires": 5
}
16 replies
CC#
Created by Salight on 2/23/2025 in #help
✅ Onion Architecture Authorization doesn't work
my extension method
16 replies
CC#
Created by Salight on 2/23/2025 in #help
✅ Onion Architecture Authorization doesn't work
public static void ConfigureJWT(this IServiceCollection services, IConfiguration
configuration)
{
var jwtConfiguration = new JwtConfiguration();
configuration.Bind(jwtConfiguration.Section, jwtConfiguration);
var secretKey = Environment.GetEnvironmentVariable("SECRET");
services.AddAuthentication(opt =>
{
opt.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
opt.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
opt.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,

ValidIssuer = jwtConfiguration.ValidIssuer,
ValidAudience = jwtConfiguration.ValidAudience,
IssuerSigningKey = new
SymmetricSecurityKey(Encoding.UTF8.GetBytes(secretKey))
};
});
}
public static void ConfigureJWT(this IServiceCollection services, IConfiguration
configuration)
{
var jwtConfiguration = new JwtConfiguration();
configuration.Bind(jwtConfiguration.Section, jwtConfiguration);
var secretKey = Environment.GetEnvironmentVariable("SECRET");
services.AddAuthentication(opt =>
{
opt.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
opt.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
opt.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,

ValidIssuer = jwtConfiguration.ValidIssuer,
ValidAudience = jwtConfiguration.ValidAudience,
IssuerSigningKey = new
SymmetricSecurityKey(Encoding.UTF8.GetBytes(secretKey))
};
});
}
16 replies
CC#
Created by Salight on 1/7/2025 in #help
I got a Mvc and an a API project i want to use [Authorize] attribute in mvc is it possible?
now it authorizes
22 replies
CC#
Created by Salight on 1/7/2025 in #help
I got a Mvc and an a API project i want to use [Authorize] attribute in mvc is it possible?
i was thinking i am getting the data from appsettings but i forget the add configure jwt settings service
22 replies
CC#
Created by Salight on 1/7/2025 in #help
I got a Mvc and an a API project i want to use [Authorize] attribute in mvc is it possible?
you were right
22 replies
CC#
Created by Salight on 1/7/2025 in #help
I got a Mvc and an a API project i want to use [Authorize] attribute in mvc is it possible?
okay bro i solved
22 replies
CC#
Created by Salight on 1/7/2025 in #help
I got a Mvc and an a API project i want to use [Authorize] attribute in mvc is it possible?
it is not actually
22 replies
CC#
Created by Salight on 1/7/2025 in #help
I got a Mvc and an a API project i want to use [Authorize] attribute in mvc is it possible?
you mean audience
22 replies
CC#
Created by Salight on 1/7/2025 in #help
I got a Mvc and an a API project i want to use [Authorize] attribute in mvc is it possible?
context.Exception.Message = "IDX10208: Unable to validate audience. validationParameters.ValidAudience is null or whitespace and validationParameters.ValidAudiences is null."
context.Exception.Message = "IDX10208: Unable to validate audience. validationParameters.ValidAudience is null or whitespace and validationParameters.ValidAudiences is null."
this is my exception btw
22 replies
CC#
Created by Salight on 1/7/2025 in #help
I got a Mvc and an a API project i want to use [Authorize] attribute in mvc is it possible?
like this
22 replies
CC#
Created by Salight on 1/7/2025 in #help
I got a Mvc and an a API project i want to use [Authorize] attribute in mvc is it possible?
public static void ConfigureJWT(this IServiceCollection services, IConfiguration
configuration)
{
var jwtConfiguration = new JwtConfiguration();
configuration.Bind(jwtConfiguration.Section, jwtConfiguration);
var secretKey = Environment.GetEnvironmentVariable("SECRET");
services.AddAuthentication(opt =>
{
opt.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
opt.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,

ValidIssuer = jwtConfiguration.ValidIssuer,
ValidAudience = jwtConfiguration.ValidAudience,
IssuerSigningKey = new
SymmetricSecurityKey(Encoding.UTF8.GetBytes(secretKey))
};
options.Events = new JwtBearerEvents
{
OnAuthenticationFailed = context =>
{
Console.WriteLine("Authentication failed: " + context.Exception.Message);
return Task.CompletedTask;
},
OnTokenValidated = context =>
{
Console.WriteLine("Token validated: " + context.SecurityToken);
return Task.CompletedTask;
}
};
});
public static void ConfigureJWT(this IServiceCollection services, IConfiguration
configuration)
{
var jwtConfiguration = new JwtConfiguration();
configuration.Bind(jwtConfiguration.Section, jwtConfiguration);
var secretKey = Environment.GetEnvironmentVariable("SECRET");
services.AddAuthentication(opt =>
{
opt.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
opt.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,

ValidIssuer = jwtConfiguration.ValidIssuer,
ValidAudience = jwtConfiguration.ValidAudience,
IssuerSigningKey = new
SymmetricSecurityKey(Encoding.UTF8.GetBytes(secretKey))
};
options.Events = new JwtBearerEvents
{
OnAuthenticationFailed = context =>
{
Console.WriteLine("Authentication failed: " + context.Exception.Message);
return Task.CompletedTask;
},
OnTokenValidated = context =>
{
Console.WriteLine("Token validated: " + context.SecurityToken);
return Task.CompletedTask;
}
};
});
22 replies