Commit dab5a2ca authored by alan.f's avatar alan.f

add-signout

parent b086707d
......@@ -45,6 +45,7 @@ namespace IdentityServer
ClientSecrets={ new Secret("client_secret_mvc".ToSha256())},
AllowedGrantTypes = GrantTypes.Code,
RedirectUris={ "https://localhost:44349/signin-oidc" },
PostLogoutRedirectUris={ "https://localhost:44349/Home/Index" },
AllowedScopes={
"ApiOne",
"ApiTwo" ,
......@@ -64,7 +65,8 @@ namespace IdentityServer
AllowedGrantTypes = GrantTypes.Implicit,
RedirectUris={ "https://localhost:44387/Home/signin" },
AllowedCorsOrigins={ "https://localhost:44387" },
PostLogoutRedirectUris={ "https://localhost:44387/Home/Idex" },
AllowedCorsOrigins={ "https://localhost:44387" },
AllowedScopes={
IdentityServerConstants.StandardScopes.OpenId,
......
......@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using IdentityServer.ViewModels;
using IdentityServer4.Services;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
......@@ -12,13 +13,16 @@ namespace IdentityServer.Controllers
{
private readonly SignInManager<IdentityUser> _signInManager;
private readonly UserManager<IdentityUser> _userManager;
private readonly IIdentityServerInteractionService _interactionService;
public AuthController(
UserManager<IdentityUser> userManager,
SignInManager<IdentityUser> signInManager)
SignInManager<IdentityUser> signInManager,
IIdentityServerInteractionService interactionService)
{
_signInManager = signInManager;
_userManager = userManager;
_interactionService = interactionService;
}
[HttpGet]
public IActionResult Login(string returnUrl)
......@@ -26,14 +30,14 @@ namespace IdentityServer.Controllers
return View(new LoginViewModel { ReturnUrl =returnUrl});
}
[HttpPost]
public async Task<IActionResult> Login(LoginViewModel vm)
{
//check if model is exsist
var result = await _signInManager.PasswordSignInAsync(vm.Username, vm.Password, false, false);
if (result.Succeeded)
var result =await _signInManager.PasswordSignInAsync(vm.Username, vm.Password, false, false);
if (result.IsNotAllowed)
{
return Redirect(vm.ReturnUrl);
}
......@@ -44,6 +48,22 @@ namespace IdentityServer.Controllers
return View();
}
[HttpGet]
public async Task<IActionResult> Logout(string logoutId)
{
await _signInManager.SignOutAsync();
var logoutRequest = await _interactionService.GetLogoutContextAsync(logoutId);
if (string.IsNullOrEmpty(logoutRequest.PostLogoutRedirectUri))
{
return RedirectToAction("Index", "Home");
}
return Redirect(logoutRequest.PostLogoutRedirectUri);
}
[HttpGet]
public IActionResult Register(string returnUrl)
{
......
......@@ -45,6 +45,7 @@ namespace IdentityServer
{
config.Cookie.Name = "IdentityServer.Cookie";
config.LoginPath = "/Auth/Login";
config.LogoutPath = "/Auth/Logout";
});
var assembly = typeof(Startup).Assembly.GetName().Name;
......@@ -59,7 +60,7 @@ namespace IdentityServer
{
options.ConfigureDbContext = b => b.UseSqlServer(connectionString,
sql => sql.MigrationsAssembly(assembly));
});
}).AddDeveloperSigningCredential();
//.AddInMemoryApiResources(Configuration.GetApis())
//.AddInMemoryIdentityResources(Configuration.GetIdentityResources())
//.AddInMemoryClients(Configuration.GetClients())
......
......@@ -27,7 +27,7 @@
<button type="submit">Sign In</button>
</div>
</form>
@*<div>
<div>
<a asp-controller="Auth" asp-action="Register"
asp-route-returnUrl="@Model.ReturnUrl">Register</a>
</div>*@
\ No newline at end of file
</div>
\ No newline at end of file
......@@ -3,7 +3,7 @@
authority: "https://localhost:44325/",
client_id: "client_id_js",
redirect_uri: "https://localhost:44387/Home/SignIn",
//post_logout_redirect_uri: "https://localhost:44345/Home/Index",
post_logout_redirect_uri: "https://localhost:44387/Home/Index",
response_type: "id_token token",
scope: "openid rc.scope ApiOne ApiTwo"
};
......@@ -14,9 +14,9 @@ var signIn = function () {
userManager.signinRedirect();
};
//var signOut = function () {
// userManager.signoutRedirect();
//};
var signOut = function () {
userManager.signoutRedirect();
};
userManager.getUser().then(user => {
console.log("user:", user);
......
......@@ -25,6 +25,11 @@ namespace MvcClient.Controllers
return View();
}
public IActionResult Logout()
{
return SignOut("Cookie","oidc");
}
[Authorize]
public async Task<IActionResult> Secret()
{
......
......@@ -27,7 +27,7 @@ namespace MvcClient
config.SaveTokens = true;
config.ResponseType = "code";
config.SignedOutCallbackPath = "/Home/Index";
//config cookie claim mapping
config.ClaimActions.DeleteClaim("amr");
config.ClaimActions.MapUniqueJsonKey("ReadaCoding.Grandma","rc.grandma");
......@@ -42,7 +42,7 @@ namespace MvcClient
config.Scope.Add("offline_access");
} );
});
services.AddHttpClient();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment