Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Modify options for Authentication in a Blazor app with OpenId out of Program.cs

$
0
0

I have a Blazor app configured to authenticate with OpenId (Auth0 in this case). In my Program.cs i have this:

var auth0Domain = builder.Configuration["Auth0:Domain"];var auth0ClientId = builder.Configuration["Auth0:ClientId"];if (!string.IsNullOrEmpty(auth0Domain) && !string.IsNullOrEmpty(auth0ClientId)){    builder.Services.AddAuthentication(options =>    {        options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;        options.DefaultChallengeScheme = Auth0Constants.AuthenticationScheme;    })    .AddOpenIdConnect("Auth0", options =>    {        options.Authority = $"https://{auth0Domain}";        options.ClientId = auth0ClientId;        //options.ClientSecret = builder.Configuration["Auth0:ClientSecret"];        options.ResponseType = "code";        options.SaveTokens = true;        options.CallbackPath = new PathString("/account/callback");        options.SkipUnrecognizedRequests = true; //ESTO RESOLVIO EL PROBLMA DE MESSAGE.STATE NULL        options.Scope.Clear();        options.Scope.Add("openid");        options.Scope.Add("profile");        options.Scope.Add("email");    });}else{    builder.Services.AddAuthentication(options =>    {        options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;    });}

And in my AccountController I have this:

[HttpGet]public async Task ExternalLogin(string redirectUrl){    string callbackUrl = redirectUrl +"account/callback";    //Console.WriteLine(callbackUrl);    var authenticationProperties = new LoginAuthenticationPropertiesBuilder()                .WithRedirectUri(callbackUrl)                .Build();    await HttpContext.ChallengeAsync(Auth0Constants.AuthenticationScheme, authenticationProperties);}

What I want is to be able to modify the Domain and the ClientId before do the ChallengeAsync. My App needs to handle differents authentication ways dependending of the user that is trying to authenticate. My users are in a database where I store the auth type they use.

I have been searching for a way to do the OpenId configuration out of my Program.cs


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>