多语言展示
当前在线:1481今日阅读:27今日分享:41

ASP.NETIdentity consent 控制器逻辑实现

ASP.NETIdentity consent 控制器逻辑实现源代码示例下载链接:pan.baidu.com/s/1Uz6JqdY9F1OttomQG4Kvrw 密码:mvo0
工具/原料

VS2017

方法/步骤
1

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;        }

3

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;        }

4

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            };        }

5

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            };        }

6

1viewpublic IActionResult Index(string returnUrl)        {            var model = BuildConsentViewModel(returnUrl);            return View(model);        }

7

完成

推荐信息