chimera
✅ Looking for a way to Extract information from a txt File
Parse each line https://stackoverflow.com/a/8038746 and you could just put everything before your : into the key in a Dictionary<string, string> and everything after into the value. That way you can easily access the values in memory
11 replies
❔ Having trouble integrating Azure ad SSO and normal username/password
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = "EQ-Bearer";
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer("EQ-Bearer", configureOptions =>
{
configureOptions.ClaimsIssuer = jwtAppSettingOptions[nameof(JwtIssuerOptions.Issuer)];
configureOptions.TokenValidationParameters = tokenValidationParameters;
configureOptions.SaveToken = true;
configureOptions.Events = new JwtBearerEvents
{
OnChallenge = context =>
{
var a = context;
return Task.CompletedTask;
},
OnAuthenticationFailed = context =>
{
if (context.Exception.GetType() == typeof(SecurityTokenExpiredException))
{
context.Response.Headers.Add("Token-Expired", "true");
}
return Task.CompletedTask;
},
OnMessageReceived = context =>
{
var accessToken = context.Request.Query["access_token"];
var path = context.HttpContext.Request.Path;
if (!string.IsNullOrEmpty(accessToken) && (path.StartsWithSegments("/hubs")))
{
context.Token = accessToken;
}
return Task.CompletedTask;
}
};
}).AddMicrosoftIdentityWebApi(Configuration);
And set the standard authentication like this:
services.AddAuthorization(options =>
{
var defaultAuthBuilder = new AuthorizationPolicyBuilder("EQ-Bearer");
defaultAuthBuilder = defaultAuthBuilder.RequireAuthenticatedUser();
options.DefaultPolicy = defaultAuthBuilder.Build();
3 replies
❔ Validate an Azure ad token in .net 7
I have also tried this,
var token = "";
string authority = "https://login.microsoftonline.com/<>/";
string clientId = "<>";
IConfigurationManager<OpenIdConnectConfiguration> configurationManager =
new ConfigurationManager<OpenIdConnectConfiguration>($"{authority}.well-known/openid-configuration", new OpenIdConnectConfigurationRetriever());
OpenIdConnectConfiguration openIdConfig = await configurationManager.GetConfigurationAsync(CancellationToken.None);
IdentityModelEventSource.ShowPII = true;
var validationParams = new TokenValidationParameters
{
ValidAudience = clientId,
IssuerSigningKeys = openIdConfig.SigningKeys,
};
openIdConfig.SigningKeys.Dump();
var tokenHandler = new JwtSecurityTokenHandler();
tokenHandler.ValidateToken(token, validationParams, out _);
but i get the error
IDX10511: Signature validation failed. Keys tried: 'Microsoft.IdentityModel.Tokens.X509SecurityKey, KeyId: '[deleted]', InternalId: '[deleted]'. , KeyId: [deleted]'.
Number of keys in TokenValidationParameters: '14'.
Number of keys in Configuration: '0'.
Matched key was in 'TokenValidationParameters'.
kid: '[deleted]'.
Exceptions caught:
".
9 replies