My Blazor application does a great job at automatically redirecting users to the AWS Cognito login but how does it generate the login URL? I would like to create a login button that a user can click to take them to AWS Cognito but it is proving to be difficult because I do not know how to generate some of the other URL query parameters such as code_challenge. Is there some sort of OIDC/Identity service I can instantiate through dependency injection to generate a sign in URL?
TLDR: There is a lot of magic in how .NET OIDC generates a login URL and I would like to figure out how to reuse that magic without having to write code to generate the Cognito login URL manually. Is there not some sort of function built into .NET OIDC or the Authentication services that will redirect a user to a configured login portal?
Here is my OIDC configuration in my Program.cs
builder.Services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect(options =>
{
options.ResponseType = builder.Configuration["Authentication:Cognito:ResponseType"];
options.MetadataAddress = builder.Configuration["Authentication:Cognito:MetadataAddress"];
options.ClientId = builder.Configuration["Authentication:Cognito:ClientId"];
})
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidIssuer = builder.Configuration["Authentication:Cognito:CognitoDomain"],
ValidateIssuerSigningKey = true,
ValidateIssuer = true,
ValidateLifetime = true,
ValidAudience = builder.Configuration["Authentication:Cognito:ClientId"],
ValidateAudience = false
};
options.MetadataAddress = builder.Configuration["Authentication:Cognito:MetadataAddress"];
});