Browse Source

Login/logout is now working for the microservice auth server demo.

pull/217/head
Halil İbrahim Kalkan 9 years ago
parent
commit
b3de11f8d3
  1. 1
      src/MicroserviceDemo/MicroserviceDemo.AuthServer/MicroserviceDemo.AuthServer.csproj
  2. 16
      src/MicroserviceDemo/MicroserviceDemo.AuthServer/MicroservicesAuthServerModule.cs
  3. 20
      src/MicroserviceDemo/MicroserviceDemo.AuthServer/Pages/Index.cshtml
  4. 17
      src/MicroserviceDemo/MicroserviceDemo.AuthServer/Pages/Index.cshtml.cs
  5. 11
      src/MicroserviceDemo/MicroserviceDemo.Web/MicroservicesDemoWebModule.cs
  6. 2
      src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Login.cshtml
  7. 17
      src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Login.cshtml.cs

1
src/MicroserviceDemo/MicroserviceDemo.AuthServer/MicroserviceDemo.AuthServer.csproj

@ -17,6 +17,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.2" />
<PackageReference Include="Serilog.Extensions.Logging" Version="2.0.2" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
</ItemGroup>

16
src/MicroserviceDemo/MicroserviceDemo.AuthServer/MicroservicesAuthServerModule.cs

@ -58,6 +58,8 @@ namespace MicroserviceDemo.AuthServer
});
}
services.AddAuthorization();
services.AddAssemblyOf<MicroservicesAuthServerModule>();
}
@ -73,7 +75,19 @@ namespace MicroserviceDemo.AuthServer
app.UseStaticFiles();
app.UseVirtualFiles();
app.UseMvcWithDefaultRoute();
app.UseAuthentication();
app.UseMvc(routes =>
{
//TODO: Can we make an extension method for adding these two routes inside the framework?
routes.MapRoute(
name: "defaultWithArea",
template: "{area}/{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
private static IConfigurationRoot BuildConfiguration(IHostingEnvironment env)

20
src/MicroserviceDemo/MicroserviceDemo.AuthServer/Pages/Index.cshtml

@ -0,0 +1,20 @@
@page
@model MicroserviceDemo.AuthServer.Pages.IndexModel
<h3>Welcome to the Authentication Server!</h3>
<abp-card>
<abp-card-header></abp-card-header>
<abp-card-body>
<a href="~/Account/Login">Login</a>
@if (User.Identity.IsAuthenticated)
{
foreach (var claim in User.Claims)
{
<div>@claim.Type = @claim.Value</div>
}
}
</abp-card-body>
</abp-card>

17
src/MicroserviceDemo/MicroserviceDemo.AuthServer/Pages/Index.cshtml.cs

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace MicroserviceDemo.AuthServer.Pages
{
public class IndexModel : PageModel
{
public void OnGet()
{
}
}
}

11
src/MicroserviceDemo/MicroserviceDemo.Web/MicroservicesDemoWebModule.cs

@ -109,7 +109,16 @@ namespace MicroserviceDemo.Web
app.UseAuthentication();
app.UseMvcWithDefaultRoute();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "defaultWithArea",
template: "{area}/{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
private static IConfigurationRoot BuildConfiguration(IHostingEnvironment env)

2
src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Login.cshtml

@ -26,7 +26,7 @@
</label>
</div>
<button type="submit" class="btn btn-primary" name="Action" value="Login">Login</button>
<button type="button" class="btn btn-secondary" name="Action" value="Cancel">Cancel</button>
<button type="button" class="btn btn-secondary" name="Action" value="Cancel">Cancel</button> @* TODO: Only show if identity server is used *@
</form>
<div style="padding-top: 20px">

17
src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Login.cshtml.cs

@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using IdentityServer4.Models;
using IdentityServer4.Services;
using IdentityServer4.Stores;
using Microsoft.AspNetCore.Authentication;
@ -112,8 +113,20 @@ namespace Volo.Abp.Account.Web.Pages.Account
}
[UnitOfWork] //TODO: Will be removed when we implement action filter
public virtual async Task<IActionResult> OnPostAsync()
public virtual async Task<IActionResult> OnPostAsync(string action)
{
if (action == "Cancel")
{
var context = await _interaction.GetAuthorizationContextAsync(ReturnUrl);
if (context == null)
{
return RedirectSafely("~/");
}
await _interaction.GrantConsentAsync(context, ConsentResponse.Denied);
return RedirectSafely(ReturnUrl);
}
ValidateModel();
var result = await _signInManager.PasswordSignInAsync(
@ -128,6 +141,8 @@ namespace Volo.Abp.Account.Web.Pages.Account
throw new UserFriendlyException("Login failed!"); //TODO: Handle other cases, do not throw exception
}
//var user = _userManager.FindByIdAsync(result.)
return RedirectSafely(ReturnUrl, ReturnUrlHash);
}

Loading…
Cancel
Save