VS2017
1相关服务注入 private readonly IClientStore _clientStore; private readonly IResourceStore _resourceStore; private readonly IIdentityServerInteractionService _identitySerfverInteractionService; public ConsentController(IClientStore clientStore, IResourceStore resourceStore, IIdentityServerInteractionService identitySerfverInteractionService) { _clientStore = clientStore; _resourceStore = resourceStore; _identitySerfverInteractionService = identitySerfverInteractionService; }
1创建CreateConsentViewModel private ConsentViewModel CreateConsentViewModel(AuthorizationRequest request, Client client, Resources resources) { var vm = new ConsentViewModel(); vm.ClientName = client.ClientName; vm.ClientLogoUrl = client.LogoUri; vm.ClientUrl = client.ClientUri; vm.AllowRememberConsent = client.AllowRememberConsent; vm.IdentityScorpes = resources.IdentityResources.Select(x => CreateScopeViewModel(x)); vm.ResourceScorps = resources.ApiResources.SelectMany(x => x.Scopes).Select(x => CreateScopeViewModel(x)); return vm; }
1创建CreateScopeViewModel private ScopeViewModel CreateScopeViewModel(IdentityResource identityResource) { return new ScopeViewModel { Name = identityResource.Name, DisplsyName = identityResource.DisplayName, Description = identityResource.Description, Checked = identityResource.Required, Required = identityResource.Required, Emphasize = identityResource.Emphasize }; }
1创建CreateScopeViewModel private ScopeViewModel CreateScopeViewModel(Scope scope) { return new ScopeViewModel { Name = scope.Name, DisplsyName = scope.DisplayName, Description = scope.Description, Checked = scope.Required, Required = scope.Required, Emphasize = scope.Emphasize }; }
1viewpublic IActionResult Index(string returnUrl) { var model = BuildConsentViewModel(returnUrl); return View(model); }
完成