public async Task <IActionResult> Edit(string id, string returnUrl = null) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageApplications)) { return(Forbid()); } var application = await _applicationManager.FindByPhysicalIdAsync(id); if (application == null) { return(NotFound()); } Task <bool> HasPermissionAsync(string permission) => _applicationManager.HasPermissionAsync(application, permission); var model = new EditOpenIdApplicationViewModel { AllowAuthorizationCodeFlow = await HasPermissionAsync(OpenIddictConstants.Permissions.GrantTypes.AuthorizationCode), AllowClientCredentialsFlow = await HasPermissionAsync(OpenIddictConstants.Permissions.GrantTypes.ClientCredentials), AllowImplicitFlow = await HasPermissionAsync(OpenIddictConstants.Permissions.GrantTypes.Implicit), AllowPasswordFlow = await HasPermissionAsync(OpenIddictConstants.Permissions.GrantTypes.Password), AllowRefreshTokenFlow = await HasPermissionAsync(OpenIddictConstants.Permissions.GrantTypes.RefreshToken), AllowLogoutEndpoint = await HasPermissionAsync(OpenIddictConstants.Permissions.Endpoints.Logout), ClientId = await _applicationManager.GetClientIdAsync(application), ConsentType = await _applicationManager.GetConsentTypeAsync(application), DisplayName = await _applicationManager.GetDisplayNameAsync(application), Id = await _applicationManager.GetPhysicalIdAsync(application), PostLogoutRedirectUris = string.Join(" ", await _applicationManager.GetPostLogoutRedirectUrisAsync(application)), RedirectUris = string.Join(" ", await _applicationManager.GetRedirectUrisAsync(application)), Type = await _applicationManager.GetClientTypeAsync(application) }; var roleService = HttpContext.RequestServices?.GetService <IRoleService>(); if (roleService != null) { var roles = await _applicationManager.GetRolesAsync(application); foreach (var role in await roleService.GetRoleNamesAsync()) { model.RoleEntries.Add(new EditOpenIdApplicationViewModel.RoleEntry { Name = role, Selected = roles.Contains(role, StringComparer.OrdinalIgnoreCase) }); } } else { _notifier.Warning(H["There are no registered services to provide roles."]); } ViewData[nameof(OpenIdServerSettings)] = await GetServerSettingsAsync(); ViewData["ReturnUrl"] = returnUrl; return(View(model)); }
public async Task <IActionResult> Edit(string id, string returnUrl = null) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageApplications)) { return(Unauthorized()); } var application = await _applicationManager.FindByPhysicalIdAsync(id); if (application == null) { return(NotFound()); } Task <bool> HasPermissionAsync(string permission) => _applicationManager.HasPermissionAsync(application, permission); var model = new EditOpenIdApplicationViewModel { AllowAuthorizationCodeFlow = await HasPermissionAsync(OpenIddictConstants.Permissions.GrantTypes.AuthorizationCode), AllowClientCredentialsFlow = await HasPermissionAsync(OpenIddictConstants.Permissions.GrantTypes.ClientCredentials), AllowImplicitFlow = await HasPermissionAsync(OpenIddictConstants.Permissions.GrantTypes.Implicit), AllowPasswordFlow = await HasPermissionAsync(OpenIddictConstants.Permissions.GrantTypes.Password), AllowRefreshTokenFlow = await HasPermissionAsync(OpenIddictConstants.Permissions.GrantTypes.RefreshToken), AllowLogoutEndpoint = await HasPermissionAsync(OpenIddictConstants.Permissions.Endpoints.Logout), ClientId = await _applicationManager.GetClientIdAsync(application), ConsentType = await _applicationManager.GetConsentTypeAsync(application), DisplayName = await _applicationManager.GetDisplayNameAsync(application), Id = await _applicationManager.GetPhysicalIdAsync(application), PostLogoutRedirectUris = string.Join(" ", await _applicationManager.GetPostLogoutRedirectUrisAsync(application)), RedirectUris = string.Join(" ", await _applicationManager.GetRedirectUrisAsync(application)), Type = await _applicationManager.GetClientTypeAsync(application) }; foreach (var role in await _roleProvider.GetRoleNamesAsync()) { model.RoleEntries.Add(new EditOpenIdApplicationViewModel.RoleEntry { Name = role, Selected = await _applicationManager.IsInRoleAsync(application, role) }); } ViewData[nameof(OpenIdServerSettings)] = await GetServerSettingsAsync(); ViewData["ReturnUrl"] = returnUrl; return(View(model)); }
public async Task <IActionResult> Edit(string id, string returnUrl = null) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageApplications)) { return(Forbid()); } var application = await _applicationManager.FindByPhysicalIdAsync(id); if (application == null) { return(NotFound()); } ValueTask <bool> HasPermissionAsync(string permission) => _applicationManager.HasPermissionAsync(application, permission); var model = new EditOpenIdApplicationViewModel { AllowAuthorizationCodeFlow = await HasPermissionAsync(OpenIddictConstants.Permissions.GrantTypes.AuthorizationCode) && await HasPermissionAsync(OpenIddictConstants.Permissions.ResponseTypes.Code), AllowClientCredentialsFlow = await HasPermissionAsync(OpenIddictConstants.Permissions.GrantTypes.ClientCredentials), // Note: the hybrid flow doesn't have a dedicated grant_type but is treated as a combination // of both the authorization code and implicit grants. As such, to determine whether the hybrid // flow is enabled, both the authorization code grant and the implicit grant MUST be enabled. AllowHybridFlow = await HasPermissionAsync(OpenIddictConstants.Permissions.GrantTypes.AuthorizationCode) && await HasPermissionAsync(OpenIddictConstants.Permissions.GrantTypes.Implicit) && (await HasPermissionAsync(OpenIddictConstants.Permissions.ResponseTypes.CodeIdToken) || await HasPermissionAsync(OpenIddictConstants.Permissions.ResponseTypes.CodeIdTokenToken) || await HasPermissionAsync(OpenIddictConstants.Permissions.ResponseTypes.CodeToken)), AllowImplicitFlow = await HasPermissionAsync(OpenIddictConstants.Permissions.GrantTypes.Implicit) && (await HasPermissionAsync(OpenIddictConstants.Permissions.ResponseTypes.IdToken) || await HasPermissionAsync(OpenIddictConstants.Permissions.ResponseTypes.IdTokenToken) || await HasPermissionAsync(OpenIddictConstants.Permissions.ResponseTypes.Token)), AllowPasswordFlow = await HasPermissionAsync(OpenIddictConstants.Permissions.GrantTypes.Password), AllowRefreshTokenFlow = await HasPermissionAsync(OpenIddictConstants.Permissions.GrantTypes.RefreshToken), AllowLogoutEndpoint = await HasPermissionAsync(OpenIddictConstants.Permissions.Endpoints.Logout), ClientId = await _applicationManager.GetClientIdAsync(application), ConsentType = await _applicationManager.GetConsentTypeAsync(application), DisplayName = await _applicationManager.GetDisplayNameAsync(application), Id = await _applicationManager.GetPhysicalIdAsync(application), PostLogoutRedirectUris = string.Join(" ", await _applicationManager.GetPostLogoutRedirectUrisAsync(application)), RedirectUris = string.Join(" ", await _applicationManager.GetRedirectUrisAsync(application)), Type = await _applicationManager.GetClientTypeAsync(application) }; var roleService = HttpContext.RequestServices?.GetService <IRoleService>(); if (roleService != null) { var roles = await _applicationManager.GetRolesAsync(application); foreach (var role in await roleService.GetRoleNamesAsync()) { model.RoleEntries.Add(new EditOpenIdApplicationViewModel.RoleEntry { Name = role, Selected = roles.Contains(role, StringComparer.OrdinalIgnoreCase) }); } } else { await _notifier.WarningAsync(H["There are no registered services to provide roles."]); } var permissions = await _applicationManager.GetPermissionsAsync(application); await foreach (var scope in _scopeManager.ListAsync()) { var scopeName = await _scopeManager.GetNameAsync(scope); model.ScopeEntries.Add(new EditOpenIdApplicationViewModel.ScopeEntry { Name = scopeName, Selected = await _applicationManager.HasPermissionAsync(application, OpenIddictConstants.Permissions.Prefixes.Scope + scopeName) }); } ViewData[nameof(OpenIdServerSettings)] = await GetServerSettingsAsync(); ViewData["ReturnUrl"] = returnUrl; return(View(model)); }