Skip to content

Commit

Permalink
Better redirect for single external auth provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Jun 28, 2019
1 parent 0dbcc5c commit d6ccd7d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ private async Task<IActionResult> LoginViewAsync(string returnUrl, bool isLogin,

var externalProviders = await signInManager.GetExternalProvidersAsync();

if (externalProviders.Count == 1 && !allowPasswordAuth)
{
var provider = externalProviders[0].AuthenticationScheme;

var properties =
signInManager.ConfigureExternalAuthenticationProperties(provider,
Url.Action(nameof(ExternalCallback), new { ReturnUrl = returnUrl }));

return Challenge(properties, provider);
}

var vm = new LoginVM
{
ExternalProviders = externalProviders,
Expand Down Expand Up @@ -242,7 +253,7 @@ public async Task<IActionResult> ExternalCallback(string returnUrl = null)

var isLoggedIn = result.Succeeded;

UserWithClaims user = null;
UserWithClaims user;

if (isLoggedIn)
{
Expand Down
11 changes: 0 additions & 11 deletions src/Squidex/Areas/IdentityServer/Views/Account/Login.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,4 @@ else
<p class="profile-footer">
Already registered? <a asp-controller="Account" asp-action="Login" asp-route-returnurl="@Model.ReturnUrl">Click here to login</a>
</p>
}

@if (!Model.HasPasswordAuth && Model.ExternalProviders.Count == 1)
{
<script>
var redirectButtons = document.getElementsByClassName("redirect-button");
if (redirectButtons.length === 1) {
redirectButtons[0].click();
}
</script>
}

0 comments on commit d6ccd7d

Please sign in to comment.