-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(issue-161): add the e-sender feature to gateway of web version
Merge pull request #170 from live-dev999/live-dev999/issue161
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...ApiGateways/O2NextGen.Web.BFF.Core/O2NextGen.Web.BFF.Core/Features/Auth/AuthController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...eways/O2NextGen.Web.BFF.Core/O2NextGen.Web.BFF.Core/Features/Auth/Models/AuthInfoModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |