private async Task <ConsentViewModel> BuildViewModelAsync(string returnUrl, ConsentInputModel model = null) { var request = await _interaction.GetAuthorizationContextAsync(returnUrl); if (request != null) { var client = await IClientStoreExtensions.FindEnabledClientByIdAsync(_clientStore, request.ClientId); if (client != null) { var resources = await IResourceStoreExtensions.FindEnabledResourcesByScopeAsync(_resourceStore, request.ScopesRequested); if (resources != null && (resources.IdentityResources.Any() || resources.ApiResources.Any())) { return(CreateConsentViewModel(model, returnUrl, request, client, resources)); } else { LoggerExtensions.LogError(_logger, "No scopes matching: {0}", Enumerable.Aggregate <string>(request.ScopesRequested, (x, y) => x + ", " + y)); } } else { LoggerExtensions.LogError(_logger, "Invalid client id: {0}", request.ClientId); } } else { LoggerExtensions.LogError(_logger, "No consent request matching request: {0}", returnUrl); } return(null); }
public async Task <ConsentViewModel> BuildViewModelAsync(string returnUrl, ConsentInputModel model = null) { var request = await this.interactionService.GetAuthorizationContextAsync(returnUrl); if (request == null) { LoggerExtensions.LogError(this.Logger, "No consent request matching request: {0}", returnUrl); return(null); } var client = await IClientStoreExtensions.FindEnabledClientByIdAsync(this.clientStore, request.ClientId); if (client == null) { LoggerExtensions.LogError(this.Logger, "Invalid client id: {0}", request.ClientId); return(null); } var resources = await IResourceStoreExtensions.FindEnabledResourcesByScopeAsync(this.resourceStore, request.ScopesRequested); if (resources != null && (resources.IdentityResources.Any() || resources.ApiResources.Any())) { return(this.CreateConsentViewModel(model, returnUrl, client, resources)); } LoggerExtensions.LogError(this.Logger, "No scopes matching: {0}", request.ScopesRequested.Aggregate((x, y) => x + ", " + y)); return(null); }
public async Task <LoginViewModel> BuildLoginViewModelAsync(string returnUrl) { var context = await _interaction.GetAuthorizationContextAsync(returnUrl); if (context?.IdP != null) { // this is meant to short circuit the UI and only trigger the one external IdP return(new LoginViewModel { EnableLocalLogin = false, ReturnUrl = returnUrl, Username = context?.LoginHint, IdentityProviders = new[] { new ExternalProvider { AuthenticationScheme = context.IdP } } }); } IEnumerable <AuthenticationScheme> schemes = await _schemeProvider.GetAllSchemesAsync(); var providers = schemes .Where(x => x.DisplayName != null || AccountOptions.WindowsAuthenticationEnabled && IsWindowsAuthenticationScheme(x) ) .Select(x => new ExternalProvider { DisplayName = IsWindowsAuthenticationScheme(x) ? AccountOptions.WindowsAuthenticationSchemeName : x.DisplayName, AuthenticationScheme = x.Name }).ToList(); var allowLocal = true; if (context?.ClientId != null) { var client = await IClientStoreExtensions.FindEnabledClientByIdAsync(_clientStore, context.ClientId); if (client != null) { allowLocal = client.EnableLocalLogin; if (client.IdentityProviderRestrictions != null && client.IdentityProviderRestrictions.Any()) { providers = providers .Where(provider => client.IdentityProviderRestrictions.Contains(provider.AuthenticationScheme)).ToList(); } } } return(new LoginViewModel { AllowRememberLogin = AccountOptions.AllowRememberLogin, EnableLocalLogin = allowLocal && AccountOptions.AllowLocalLogin, ReturnUrl = returnUrl, Username = context?.LoginHint, IdentityProviders = providers.ToArray() }); }