Jump to content

OpenID integration with WHMCS in C# & Blazor


Bikbokken

Recommended Posts

HI!

I've tried integrating WHMCS with my blazor project.

My Startup.cs is the following:

namespace ClientSite
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }
        public IConfiguration Configuration { get; }
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages();
            services.AddServerSideBlazor();
            services.AddSingleton<WeatherForecastService>();
            IdentityModelEventSource.ShowPII = true;
            services.AddAuthentication(options =>
            {
                options.DefaultScheme = "Cookies";
                options.DefaultChallengeScheme = "oidc";
            })
            .AddCookie("Cookies")
            .AddOpenIdConnect("oidc", options =>
            {
                options.Authority = "https://domain/oauth/openid-configuration.php";
                options.ClientId = "xxxxxxxxxxxx"; // 75 seconds
                options.ClientSecret = "xxxxxxxxxxxxxxxx";
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    IssuerSigningKeyResolver = (token, securityToken, kid, parameters) =>
                    {
                        var client = new HttpClient();
                        var response = client.GetAsync("https://domain/oauth/certs.php").Result;
                        var responseString = response.Content.ReadAsStringAsync().Result;
                        var keys = JsonConvert.DeserializeObject<JwkListcs>(responseString);

                        return keys.Keys;
                    },
                    ValidIssuers = new List<string>
                    {
                        "https://domain/"
                    }
                };
                options.ResponseType = "code";
                options.SaveTokens = true;
                options.Configuration = new OpenIdConnectConfiguration
                {
                    AuthorizationEndpoint = "https://domain/oauth/authorize.php",
                    JwksUri = "https://domain/oauth/certs.php",
                    TokenEndpoint = "https://domain/oauth/token.php",
                    UserInfoEndpoint = "https://domain/oauth/userinfo.php",
                    Issuer = "https://domain",
                };
                options.GetClaimsFromUserInfoEndpoint = true;
                options.Events = new OpenIdConnectEvents
                {
                    OnAccessDenied = context =>
                    {
                        context.HandleResponse();
                        context.Response.Redirect("/");
                        return Task.CompletedTask;
                    }
                };
            });
            services.AddSingleton<BlazorServerAuthStateCache>();
            services.AddScoped<AuthenticationStateProvider, BlazorServerAuthState>();
        }
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseAuthentication();
            app.UseRouting();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapBlazorHub();
                endpoints.MapFallbackToPage("/_Host");
            });
        }
    }
}

But after logging in and being redirected back to my page, i get this error. (attached image)

image.thumb.png.c56d50743a63456994668a1a5b02d6ad.png

Does anyone know the solution to this problem?

 

Thanks in advance.

- Bikbokken. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated