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); ValueTask <bool> HasRequirementAsync(string requirement) => _applicationManager.HasRequirementAsync(application, requirement); 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), AllowIntrospectionEndpoint = await HasPermissionAsync(OpenIddictConstants.Permissions.Endpoints.Introspection), AllowRevocationEndpoint = await HasPermissionAsync(OpenIddictConstants.Permissions.Endpoints.Revocation), 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), RequireProofKeyForCodeExchange = await HasRequirementAsync(OpenIddictConstants.Requirements.Features.ProofKeyForCodeExchange) }; 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)); }