Skip to content

Commit

Permalink
feat(issue-161): add the e-sender feature to gateway of web version
Browse files Browse the repository at this point in the history
Merge pull request #170 from live-dev999/live-dev999/issue161
  • Loading branch information
live-dev999 authored Jan 22, 2022
2 parents 31218d4 + 4f9b8de commit 17347e9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Microsoft.AspNetCore.Antiforgery;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using O2NextGen.Web.BFF.Core.Features.Auth.Models;

namespace O2NextGen.Web.BFF.Core.Features.Auth
{
[Route("auth")]
public class AuthController : ControllerBase
{
private readonly IAntiforgery _antiForgery;

public AuthController(IAntiforgery antiForgery)
{
_antiForgery = antiForgery;
}

[HttpGet]
[Route("info")]
public ActionResult<AuthInfoModel> GetInfo()
{
var tokens = _antiForgery.GetAndStoreTokens(HttpContext);
HttpContext.Response.Cookies.Append(
"XSRF-TOKEN",
tokens.RequestToken,
//allow JS to grab the cookie to put it in the request header
new CookieOptions() {HttpOnly = false});

return new AuthInfoModel
{
Name = User.FindFirst("name").Value
};
}

/*
* No need to do anything here, as the auth middleware will take care of redirecting to IdentityServer4.
* When the user is authenticated and gets back here, we can redirect to the desired url.
*/
[HttpGet]
[Route("login")]
public IActionResult Login([FromQuery] string returnUrl)
{
return Redirect(string.IsNullOrWhiteSpace(returnUrl) ? "/" : returnUrl);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace O2NextGen.Web.BFF.Core.Features.Auth.Models
{
public class AuthInfoModel
{
public string Name { get; set; }
}
}

0 comments on commit 17347e9

Please sign in to comment.