MVC Core 6.0 Trying to get the example work

Hello,
I’m trying to reproduce this example :

But I feel that the /callback is not handled by the Auth0 SDK.

I probably miss something.
I’ve created a new project with the visual studio template “ASP.NET Core Web App (Model View Controller)” on the “Additional information” I’ve set :
“Framework” =“.NET 6.0 (Long Term Support)
“Authentication Type” = “None”
Check “Configure for HTTPS”
Uncheck “Enable Docker”
Check “Do not use top-level statments”
the code in my program.cs :
public static void Main(string args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAuth0WebAppAuthentication(options => {
options.Domain = builder.Configuration[“Auth0:Domain”];
options.ClientId = builder.Configuration[“Auth0:ClientId”];
});
builder.Services.AddControllersWithViews();
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler(”/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(name: “default”,pattern: “{controller=Home}/{action=Index}/{id?}”);
app.Run();
}

I’m using the nuget package "Auth0.AspNetCore.Authentication 1.0.4 "

the account controller and the views are copy pasted from GitHub - auth0-samples/auth0-aspnetcore-mvc-samples: Auth0 Integration Samples for ASP.NET Core MVC Web Applications ( with namespage changed)

Can you help me ?

Thank you
Geoffroy

Hi @gperrier

Welcome to the Auth0 Community.

Is there any specific issue/error you have in running the sample? I tested this out by downloading the sample from here https://auth0.com/docs/quickstart/webapp/aspnet-core and I was able to get this to work with .NET 6.0

My csproj looks like this:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Auth0.AspNetCore.Authentication" Version="1.0.3" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.2.0" />
  </ItemGroup>
</Project>

Warm regards.

2 Likes

Hi SaqibHussain,
Thank you for the feedback
The reference was missing in my project , but it still not work.

image
I’m login well then the redirection is done with the token the cookie is also set but the App don’t handle it


I’m goging to clone the project from github. But I’ll need to integrate it into an existing project , So I’ve to get it Work from scratch.

Thank you

Ok I’ve found what was missing :
this block

app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
});

after
app.UseAuthentication();
app.UseAuthorization();

Problem Solved
Thank you

2 Likes

No worries! We’ve all been there! Thanks for sharing it with the rest of community!