Fix wrong returnUrl in callback

This commit is contained in:
Enes Sadık Özbek 2019-05-02 00:58:52 +03:00
parent a07646e608
commit e64380326f

View file

@ -9,6 +9,7 @@ using Microsoft.Extensions.Logging;
namespace SteamOpenIdConnectProxy namespace SteamOpenIdConnectProxy
{ {
[AllowAnonymous] [AllowAnonymous]
[Route("[action]")]
public class ExternalLoginController : Controller public class ExternalLoginController : Controller
{ {
private readonly SignInManager<IdentityUser> _signInManager; private readonly SignInManager<IdentityUser> _signInManager;
@ -27,30 +28,29 @@ namespace SteamOpenIdConnectProxy
[HttpGet] [HttpGet]
[Route("/ExternalLogin")] public async Task<IActionResult> ExternalLogin(string returnUrl = null)
public async Task<IActionResult> Login(string returnUrl = null)
{ {
string provider = "Steam"; string provider = "Steam";
// Request a redirect to the external login provider. // Request a redirect to the external login provider.
var redirectUrl = "/ExternalLoginCallback?returnUrl=" + Uri.EscapeUriString(returnUrl); var redirectUrl = Url.Action("ExternalLoginCallback", new { returnUrl });
var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl); var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
return new ChallengeResult(provider, properties); return new ChallengeResult(provider, properties);
} }
[HttpGet] [HttpGet]
[Route("/ExternalLoginCallback")] public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null)
public async Task<IActionResult> Callback(string returnUrl = null, string remoteError = null)
{ {
returnUrl = returnUrl ?? Url.Content("~/"); returnUrl = returnUrl ?? Url.Content("~/");
if (remoteError != null) if (remoteError != null)
{ {
return Content($"Error from external provider: {remoteError}"); throw new Exception($"Error from external provider: {remoteError}");
} }
var info = await _signInManager.GetExternalLoginInfoAsync(); var info = await _signInManager.GetExternalLoginInfoAsync();
if (info == null) if (info == null)
{ {
return Content($"Error loading external login information."); throw new Exception($"Error loading external login information.");
} }
// Sign in the user with this external login provider if the user already has a login. // Sign in the user with this external login provider if the user already has a login.