I have a .NET Blazor Server application with Auth0 hooked up and 95% working. The part that isn’t working, and perhaps I have this wrong, but the callback I’ve specified isn’t being called after a successful login. The application instead just redirects to my home page (Index.razor).
What I expect the application do is redirect me to my callback where, in theory, I can perform additional logic around the user. This would be things like:
- Logging the successful user login
- Creating a user account in my DB (where I track their preferences, etc.)
- Setting additional user context with meta-data from my DB
I’ve set the callback path in my Program.cs file via the Builder.Services delegate (this actually fixed an error message when wiring up the application initially), but when I create a razor page (callback.cshtml) and it’s corresponding OnGet() function, no code in that method ever gets called.
Am I doing something wrong? Does anyone have an example of a working callback page (both markup and code behind, if necessary) that I can try out?
Thanks for getting in touch with us at Auth0 Community.
I would recommend you review this https://auth0.com/blog/what-is-blazor-tutorial-on-building-webapp-with-authentication/ if you haven’t already done so.
I’m assuming you’re using the Auth0 ASP.NET Core Authentication SDK which is a wrapper around OpenId Connect. The /callback isn’t necessarily a page you need to create but it gets processed internally by the OpenId Connect middleware. After successful auth most likely you will be returned to your homepage. I expect from there you may call other aspects of you application to do whatever custom processing is required.
I have read it and have implemented it successfully wherein my application redirects to the home page.
I do not want, however, my application to redirect to my homepage. I want it to redirect to a callback page to do any post login logic/processing. The index page is not the proper page to do any of that. If I implemented this pattern (or anyone for that matter), every time someone visits the home page, that post-authentication logic would get executed. This is unnecessary.
I’d like an example of how one might implement a proper authentication callback in Blazor. Searching the web is proving difficult as the SDK obfuscates (as it should) the necessary plumbing a callback would need. If additional plumbing is needed in the
Startup.cs file (or any additional files) to wire up a callback, that would be super helpful.
I redirect this thread to our other thread in case other people have the same question.
For future reference @andrea.chiarelli I believe you can also merge topics into one to make it easier to navigate!