Skip to content

Commit

Permalink
fix authentication issue in mvc sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre SPIESER committed Mar 16, 2021
1 parent 94d8f6b commit 35ab8de
Show file tree
Hide file tree
Showing 7 changed files with 499 additions and 916 deletions.
8 changes: 4 additions & 4 deletions sample/MongoIdentitySample.Mvc/MongoIdentitySample.Mvc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\AspNetCore.Identity.MongoDbCore.csproj" />
</ItemGroup>

<ItemGroup>
<Content Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<!-- Select one of the following to build this solution -->
<ItemGroup>
<!-- <PackageReference Include="AspNetCore.Identity.MongoDbCore" Version="3.1.0" /> -->
<ProjectReference Include="..\..\src\AspNetCore.Identity.MongoDbCore.csproj" />
</ItemGroup>

</Project>
21 changes: 19 additions & 2 deletions sample/MongoIdentitySample.Mvc/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,29 @@ public void ConfigureServices(IServiceCollection services)

services.AddSingleton<MongoDbSettings>(settings);

services.AddIdentity<ApplicationUser, MongoIdentityRole>()
services.AddAuthentication(o =>
{
o.DefaultScheme = IdentityConstants.ApplicationScheme;
o.DefaultSignInScheme = IdentityConstants.ExternalScheme;
})
.AddIdentityCookies(o => { });

services.AddIdentityCore<ApplicationUser>()
.AddRoles<MongoIdentityRole>()
.AddMongoDbStores<ApplicationUser, MongoIdentityRole, Guid>(settings.ConnectionString, settings.DatabaseName)
.AddSignInManager()
.AddDefaultTokenProviders();

services.ConfigureApplicationCookie(options =>
{
// Cookie settings
options.Cookie.HttpOnly = true;
options.ExpireTimeSpan = TimeSpan.FromMinutes(5);

options.LoginPath = "/Account/Login";
options.SlidingExpiration = true;
});


var builder = services.AddRazorPages();

Expand All @@ -70,7 +88,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
Expand Down
Loading

0 comments on commit 35ab8de

Please sign in to comment.