Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement external login only. #2177

Merged
merged 2 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using IdentityModel;
using IdentityModel;
using IdentityServer4.Events;
using IdentityServer4.Models;
using IdentityServer4.Services;
Expand All @@ -12,8 +12,10 @@
using System.Security.Claims;
using System.Security.Principal;
using System.Threading.Tasks;
using Volo.Abp.Account.Web.Settings;
using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Settings;
using Volo.Abp.Uow;

namespace Volo.Abp.Account.Web.Pages.Account
Expand All @@ -40,7 +42,7 @@ public IdentityServerSupportedLoginModel(
IdentityServerEvents = identityServerEvents;
}

public override async Task OnGetAsync()
public override async Task<IActionResult> OnGetAsync()
{
LoginInput = new LoginInputModel();

Expand All @@ -63,7 +65,7 @@ public override async Task OnGetAsync()
{
LoginInput.UserNameOrEmailAddress = context.LoginHint;
ExternalProviders = new[] { new ExternalProviderModel { AuthenticationScheme = context.IdP } };
return;
return Page();
}

var schemes = await _schemeProvider.GetAllSchemesAsync();
Expand All @@ -77,7 +79,7 @@ public override async Task OnGetAsync()
})
.ToList();

EnableLocalLogin = true; //TODO: We can get default from a setting?
EnableLocalLogin = await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin);
if (context?.ClientId != null)
{
var client = await ClientStore.FindEnabledClientByIdAsync(context.ClientId);
Expand All @@ -96,15 +98,16 @@ public override async Task OnGetAsync()

if (IsExternalLoginOnly)
{
//return await ExternalLogin(vm.ExternalLoginScheme, returnUrl);
throw new NotImplementedException();
return await base.OnPostExternalLogin(providers.First().AuthenticationScheme);
}

return Page();
}

[UnitOfWork] //TODO: Will be removed when we implement action filter
public override async Task<IActionResult> OnPostAsync(string action)
{
EnableLocalLogin = true; //TODO: We can get default from a setting?
EnableLocalLogin = await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin);

if (action == "Cancel")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ public LogoutController(SignInManager<IdentityUser> signInManager)
}

//todo@alper: this method can be moved to AccountController like "account/logout"
public async Task<IActionResult> Index()
public async Task<IActionResult> Index(string returnUrl = null)
{
await _signInManager.SignOutAsync();

if (returnUrl != null)
{
return LocalRedirect(returnUrl);
}

return RedirectToPage("/Account/Login");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Volo.Abp.Account.Web.Settings;
using Volo.Abp.Identity;
using Volo.Abp.Security.Claims;
using Volo.Abp.Settings;
using Volo.Abp.Uow;
using Volo.Abp.Validation;
using IdentityUser = Volo.Abp.Identity.IdentityUser;
Expand Down Expand Up @@ -56,7 +58,7 @@ public LoginModel(
_accountOptions = accountOptions.Value;
}

public virtual async Task OnGetAsync()
public virtual async Task<IActionResult> OnGetAsync()
{
LoginInput = new LoginInputModel();

Expand All @@ -71,21 +73,23 @@ public virtual async Task OnGetAsync()
})
.ToList();

EnableLocalLogin = true; //TODO: We can get default from a setting?
EnableLocalLogin = await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin);

ExternalProviders = providers.ToArray();

if (IsExternalLoginOnly)
{
//return await ExternalLogin(vm.ExternalLoginScheme, returnUrl);
throw new NotImplementedException();
}

return Page();
}

[UnitOfWork] //TODO: Will be removed when we implement action filter
public virtual async Task<IActionResult> OnPostAsync(string action)
{
EnableLocalLogin = true; //TODO: We can get default from a setting?
EnableLocalLogin = await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin);

ValidateModel();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ public override void Define(ISettingDefinitionContext context)
context.Add(
new SettingDefinition(AccountSettingNames.IsSelfRegistrationEnabled, "true")
);

context.Add(
new SettingDefinition(AccountSettingNames.EnableLocalLogin, "true")
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
public class AccountSettingNames
{
public const string IsSelfRegistrationEnabled = "Abp.Account.IsSelfRegistrationEnabled";

public const string EnableLocalLogin = "Abp.Account.EnableLocalLogin";
}
}