public async Task <IActionResult> Index(InputConsentViewModel viewmodel) { // viewmodel.ReturlUrl ConsentResponse consentResponse = null; if (viewmodel.Button == "no") { consentResponse = ConsentResponse.Denied; } else { if (viewmodel.ScopesConsented != null && viewmodel.ScopesConsented.Any()) { consentResponse = new ConsentResponse { RememberConsent = viewmodel.RemeberConsent, ScopesConsented = viewmodel.ScopesConsented }; } } if (consentResponse != null) { var request = await _identityServerInteractionService.GetAuthorizationContextAsync(viewmodel.ReturnUrl); await _identityServerInteractionService.GrantConsentAsync(request, consentResponse); return(Redirect(viewmodel.ReturnUrl)); } return(View(await BuildConsentViewModel(viewmodel.ReturnUrl))); }
public async Task <ProcessConsentResult> PorcessConsentAsync(InputConsentViewModel viewModel) { ConsentResponse consentResponse = null; var result = new ProcessConsentResult(); if (viewModel.Button == "no") { consentResponse = ConsentResponse.Denied; } else if (viewModel.Button == "yes") { if (viewModel.ScopecConsented != null && viewModel.ScopecConsented.Any()) { consentResponse = new ConsentResponse { RememberConsent = viewModel.RemeberConsent, ScopesConsented = viewModel.ScopecConsented }; } result.ValidationError = "请至少选中一个权限"; } if (consentResponse != null) { var request = await _identityServerInteractionService.GetAuthorizationContextAsync(viewModel.ReturnUrl); await _identityServerInteractionService.GrantConsentAsync(request, consentResponse); result.RedirectUrl = viewModel.ReturnUrl; } var consentViewModel = await BuildConsentViewModelAsync(viewModel.ReturnUrl, viewModel); result.viewModel = consentViewModel; return(result); }
public async Task <IActionResult> Index([FromForm] InputConsentViewModel inputModel) { ConsentResponse consentResponse = null; if (inputModel.Button == "no") { consentResponse = ConsentResponse.Denied; } else if (inputModel.Button == "yes") { if (inputModel.ScopesConsented?.Any() ?? false) { consentResponse = new ConsentResponse { ScopesConsented = inputModel.ScopesConsented, RememberConsent = inputModel.RememberConsent }; } } if (consentResponse != null) { var request = await _identityServerInteractionService.GetAuthorizationContextAsync(inputModel.ReturnUrl); await _identityServerInteractionService.GrantConsentAsync(request, consentResponse); return(Redirect(inputModel.ReturnUrl)); } throw new Exception("error"); }
public async Task <IActionResult> Index(InputConsentViewModel viewModel) { ConsentResponse consentResponse = null; if (viewModel.Button == "no") { consentResponse = ConsentResponse.Denied; } else if (viewModel.Button == "yes") { if (viewModel.ScopesConsented != null && viewModel.ScopesConsented.Any()) { consentResponse = new ConsentResponse { ScopesConsented = viewModel.ScopesConsented, RememberConsent = viewModel.RememberConsent }; } } if (consentResponse != null) { await consentService.SaveConsentViewModel(consentResponse, viewModel.ReturnUrl); return(Redirect(viewModel.ReturnUrl)); } if (consentResponse == null) { ModelState.AddModelError("", "请至少选中一个权限"); } return(View()); }
public async Task <IActionResult> Index(InputConsentViewModel viewModel) { viewModel.Button = "yes"; ConsentResponse response = null; if (viewModel.Button == "no") { response = ConsentResponse.Denied; } else if (viewModel.Button == "yes") { if (viewModel.ScopedConsent != null && viewModel.ScopedConsent.Any()) { response = new ConsentResponse() { RememberConsent = viewModel.RememberConsent, ScopesConsented = viewModel.ScopedConsent }; } } if (response != null) { var res = await _identityServerInteractionService.GetAuthorizationContextAsync(viewModel.ReturnUrl); await _identityServerInteractionService.GrantConsentAsync(res, response); Redirect(viewModel.ReturnUrl); } return(View()); }
public async Task <IActionResult> Index(string returnUrl, InputConsentViewModel viewModel = null) { var model = await _consentService.BuildConsentViewModel(returnUrl, viewModel); if (model == null) { } return(View(model)); }
public async Task <IActionResult> Index(InputConsentViewModel viewModel) { var result = await _consentService.ProcessConsent(viewModel); if (result.IsCallBack) { return(Redirect(result.ReditectUrl)); } return(View(viewModel)); }
/// <summary> /// BuildConsentViewModel /// </summary> /// <param name="ReturnUrl"></param> /// <param name="model">二次选中的时候发生作用</param> /// <returns></returns> public async Task <ConsentViewModel> BuildConsentViewModel(string ReturnUrl, InputConsentViewModel model = null) { var request = await _identityServerInteractionService.GetAuthorizationContextAsync(ReturnUrl); if (request == null) { return(null); } var vm = CreateConsentViewModel(request, model); vm.ReturnUrl = ReturnUrl; return(vm); }
public async Task <IActionResult> Index(InputConsentViewModel viewModel) { var result = await _consentService.ProcessConsent(viewModel); if (result.IsRedirect) { return(Redirect(result.RedirectUrl)); } if (!string.IsNullOrEmpty(result.ValidationError)) { ModelState.AddModelError("", result.ValidationError); } return(View(result.ViewModel)); }
public async Task <IActionResult> Index(InputConsentViewModel inputConsent) { var result = await _consentService.ProcessConsentAsync(inputConsent); if (result.IsRedirect) { return(Redirect(result.RedirectUrl)); } // 如果不跳转,则继续返回Index视图 if (!string.IsNullOrEmpty(result.ValidationError)) { ModelState.AddModelError("", result.ValidationError); // key没有传值 } return(View(result.consentViewModel)); // 填充Index视图,需要ConsentViewModel的对象 }
public async Task <IActionResult> Index(InputConsentViewModel inputConsentViewModel) { var processConsentResult = await _consentService.ProceedConsent(inputConsentViewModel); if (processConsentResult.IsReturnUrl) { return(Redirect(processConsentResult.ReturnUrl)); } if (!string.IsNullOrEmpty(processConsentResult.ValidateErrorMessage)) { ModelState.AddModelError("", processConsentResult.ValidateErrorMessage); } return(View(processConsentResult.consentViewModel)); }
/// <summary> /// /// </summary> /// <param name="returnUrl"></param> /// <param name="model">二次选中的时候发生作用</param> /// <returns></returns> public async Task <ConsentViewModel> BuildConsentViewModel(string returnUrl, InputConsentViewModel model = null) { var request = await _identityServerInteractionService.GetAuthorizationContextAsync(returnUrl); if (request == null) { return(null); } var client = await _clientStore.FindEnabledClientByIdAsync(request.ClientId); var resources = await _resourceStore.FindEnabledResourcesByScopeAsync(request.ScopesRequested); var vm = CreateConsentViewModel(request, client, resources, model); vm.ReturnUrl = returnUrl; return(vm); }
public async Task <ProcessConsentResult> ProcessConsent(InputConsentViewModel viewModel) { ConsentResponse consentResponse = null; var result = new ProcessConsentResult(); switch (viewModel.Button) { case "no": consentResponse = ConsentResponse.Denied; break; case "yes": if (viewModel.ScopesConsented != null && viewModel.ScopesConsented.Any()) { consentResponse = new ConsentResponse() { ScopesConsented = viewModel.ScopesConsented, RememberConsent = viewModel.RememberConsent }; } else { result.ValidationError = "请至少选择一个信息!"; } break; } if (consentResponse != null) { var request = await _identityServer.GetAuthorizationContextAsync(viewModel.ReturnUrl); await _identityServer.GrantConsentAsync(request, consentResponse); result.RedirectUrl = viewModel.ReturnUrl; } else { var consentViewModel = await BuildConsentViewModelAsync(viewModel.ReturnUrl, viewModel); result.ViewModel = consentViewModel; } return(result); }
private ConsentViewModel CreateConsentViewModel(AuthorizationRequest request, Client client, Resources resources, InputConsentViewModel model) { var rememberConsent = model?.RememberConsent ?? true; var selectedScopes = model?.ScopesConsented ?? Enumerable.Empty <string>(); var vm = new ConsentViewModel(); vm.ClientName = client.ClientName; vm.ClientLogoUrl = client.LogoUri; vm.ClientUrl = client.ClientUri; vm.RememberConsent = rememberConsent; vm.IdentityScopes = resources.IdentityResources.Select(i => CreateScopeViewModel(i, selectedScopes.Contains(i.Name) || model == null)); vm.ResourceScopes = resources.ApiResources.SelectMany(i => i.Scopes).Select(i => CreateScopeViewModel(i, selectedScopes.Contains(i.Name) || model == null)); return(vm); }
public async Task <ProcessConsentResult> ProcessConsentAsync(InputConsentViewModel inputConsent) { ProcessConsentResult result = new ProcessConsentResult(); ConsentResponse consentResponse = null; if (inputConsent.Button == "no") { consentResponse = ConsentResponse.Denied; } else if (inputConsent.Button == "yes") { if (inputConsent.ScopesConsented != null && inputConsent.ScopesConsented.Any()) { consentResponse = new ConsentResponse { RememberConsent = inputConsent.RememberConsent, ScopesConsented = inputConsent.ScopesConsented }; } else { // 一个权限都没有选,给校验错误提示 result.ValidationError = "Please select at least one permission!"; } } if (consentResponse != null) { //构造 Redirect return url var requestContext = await _identityServerInteractionService.GetAuthorizationContextAsync(inputConsent.ReturnUrl); await _identityServerInteractionService.GrantConsentAsync(requestContext, consentResponse); //告诉identityServer 用户做了哪些授权(同意 / 取消) //return Redirect(inputConsent.ReturnUrl); result.RedirectUrl = inputConsent.ReturnUrl; } else { // 如果consentResponse=null,即什么权限都没有选中,那么继续返回Index视图,这时实例化ConsentViewModel的对象 var consentViewModel = await BuildConsentViewModelAsync(inputConsent.ReturnUrl, inputConsent); result.consentViewModel = consentViewModel; } return(result); }
public async Task <ConsentViewModel> BuildConsentViewModel(string returnUrl, InputConsentViewModel inputConsentViewModel = null) { //这个 returnUrl是在consent页中获取的必须带上这个请求页才能得到信息 var request = await _identityServerInteractionService.GetAuthorizationContextAsync(returnUrl); if (request == null) { return(null); } var client = await _clientStore.FindClientByIdAsync(request.ClientId); var resources = await _resourceStore.FindEnabledResourcesByScopeAsync(request.ScopesRequested);// 所以这个scope就是代表这个客户端可以请求的api 或者获得的资源的名称? var model = CreateConsentViewModel(request, client, resources, inputConsentViewModel); model.ReutrnUrl = returnUrl; return(model); }
public async Task <ProcessConsentResult> ProceedConsent(InputConsentViewModel inputConsentViewModel) { ProcessConsentResult processConsentResult = new ProcessConsentResult(); ConsentResponse consentResponse = null; if (inputConsentViewModel.Button == "yes") { if (inputConsentViewModel.scopeItems != null && inputConsentViewModel.scopeItems.Any()) { consentResponse = new ConsentResponse(); consentResponse.RememberConsent = inputConsentViewModel.RemenberConsent; consentResponse.ScopesConsented = inputConsentViewModel.scopeItems; } else { processConsentResult.ValidateErrorMessage = "请选择授权"; } } else { consentResponse = ConsentResponse.Denied;//拒绝授权 } if (consentResponse != null) { var request = await _identityServerInteractionService.GetAuthorizationContextAsync(inputConsentViewModel.ReutrnUrl); await _identityServerInteractionService.GrantConsentAsync(request, consentResponse);//不太明白这一步,是确定授权然后自动记录到数据? //这里是跳转回当前授权服务器的页面的 //return Redirect(inputConsentViewModel.ReutrnUrl); processConsentResult.ReturnUrl = inputConsentViewModel.ReutrnUrl; } else { ConsentViewModel consentViewModel = await BuildConsentViewModel(inputConsentViewModel.ReutrnUrl); processConsentResult.consentViewModel = consentViewModel; } return(processConsentResult); }
public async Task <ProcessConsetnResult> ProcessConsent(InputConsentViewModel model) { var result = new ProcessConsetnResult() { }; ConsentResponse consentResponse = null; if (model.Button == "no") { consentResponse = ConsentResponse.Denied; } else if (model.Button == "yes") { if (model.ScopesConsented != null && model.ScopesConsented.Any()) { consentResponse = new ConsentResponse { RememberConsent = model.RememberConsent, ScopesConsented = model.ScopesConsented }; } else { result.ValidationError = "请至少选择一个"; } } if (consentResponse != null) { var request = await _identityServerInteractionServer.GetAuthorizationContextAsync(model.ReturnUrl); await _identityServerInteractionServer.GrantConsentAsync(request, consentResponse); result.RedirectUrl = model.ReturnUrl; } var consentViewModel = await BuildConsentViewModelAsync(model.ReturnUrl, model); result.ViewModel = consentViewModel; return(result); }
public async Task <ConsentGrantProceResult> ConsentGrantProce(InputConsentViewModel model) { ConsentResponse consentResponse = null; var result = new ConsentGrantProceResult(); if (model.Button == "no") { consentResponse = new ConsentResponse { Error = AuthorizationError.AccessDenied }; } else if (model.Button == "yes") { if (model.ScopesConsented != null && model.ScopesConsented.Any()) { consentResponse = new ConsentResponse { RememberConsent = model.AllowRememberConsent, ScopesValuesConsented = model.ScopesConsented }; } else { result.ValidateError = "请至少选中一个权限"; } } if (consentResponse != null) { var request = await _identityServerInteractionService.GetAuthorizationContextAsync(model.ReturnUrl); await _identityServerInteractionService.GrantConsentAsync(request, consentResponse); result.RedirectUri = model.ReturnUrl; } else { result.ConsentViewModel = await BindConsentViewModelAsync(model.ReturnUrl, model); } return(result); }
public async Task <ProcessConsentResult> ProcessConsent(InputConsentViewModel model) { ConsentResponse response = null; var result = new ProcessConsentResult(); if (model.Button == "no") { response = new ConsentResponse { Error = AuthorizationError.AccessDenied }; } else if (model.Button == "yes") { if (model.ScopesConsented != null && model.ScopesConsented.Any()) { response = new ConsentResponse() { ScopesValuesConsented = model.ScopesConsented.ToArray(), RememberConsent = model.RememberConsent }; } result.ValidationError = "请至少选中一个权限"; } if (response != null) { var request = await _identityServerInteractionService.GetAuthorizationContextAsync(model.ReturnUrl); await _identityServerInteractionService.GrantConsentAsync(request, response); result.RedirectUrl = model.ReturnUrl; } else { var consentViewModel = await BuildConsentViewModel(model.ReturnUrl, model); result.consentViewModel = consentViewModel; } return(result); }
public async Task <ProcessConsentResult> PorcessConsent(InputConsentViewModel model) { ConsentResponse consent = null; var result = new ProcessConsentResult(); if (model != null) { if (model.Button == "no") { consent = ConsentResponse.Denied;// 拒绝授权 } else if (model.Button == "yes") { if (model.ScopesConsented != null && model.ScopesConsented.Any()) { consent = new ConsentResponse { RememberConsent = model.RemeberConsent, ScopesConsented = model.ScopesConsented }; } result.ValidationError = "请至少选中一个权限"; } } if (consent != null) { var response = await _identityServerInteractionService.GetAuthorizationContextAsync(model.ReturnUrl); await _identityServerInteractionService.GrantConsentAsync(response, consent);// 通知用户同意 result.RedirectUrl = model.ReturnUrl; } else { result.ConsentViewModel = await BuildConsentViewModel(model.ReturnUrl, model); } return(result); }
public async Task <ProcessConsentResult> ProcessConsent(InputConsentViewModel viewModel) { ConsentResponse consentResponse = null; if (viewModel.Button == "no") { consentResponse = ConsentResponse.Denied; } else if (viewModel.Button == "yes") { if (viewModel.ScopesConsented != null && viewModel.ScopesConsented.Any()) { consentResponse = new ConsentResponse { RememberConsent = viewModel.RemeberConsent, ScopesConsented = viewModel.ScopesConsented, }; } } ProcessConsentResult result = new ProcessConsentResult(); if (consentResponse != null) { var response = await _identityServerInteractionService.GetAuthorizationContextAsync(viewModel.ReturnUrl); await _identityServerInteractionService.GrantConsentAsync(response, consentResponse); result.ReditectUrl = viewModel.ReturnUrl; } var consentViewModel = await BuildConsentViewModel(viewModel.ReturnUrl); result.ViewModel = consentViewModel; return(result); }
public async Task <ProcessConsentResult> ProcessConsent(InputConsentViewModel vm) { ConsentResponse consentResp = null; var result = new ProcessConsentResult(); if (vm.Button == "no") { consentResp = ConsentResponse.Denied; } else if (vm.Button == "yes") { if (vm.ScopesConsented != null && vm.ScopesConsented.Any()) { consentResp = new ConsentResponse { RememberConsent = vm.RememberConsent, ScopesConsented = vm.ScopesConsented }; } result.ValidationError = "请至少选中一个权限"; } if (consentResp != null) { var req = await _identityServerInteractionService.GetAuthorizationContextAsync(vm.ReturnUrl); await _identityServerInteractionService.GrantConsentAsync(req, consentResp); result.RedirectUrl = vm.ReturnUrl; } { var consentvm = await BuildConsentViewModel(vm.ReturnUrl, vm); result.ConsentViewModel = consentvm; } return(result); }
private ConsentViewModel CreateConsentViewModel(AuthorizationRequest request, InputConsentViewModel model) { var rememberConsent = model?.RememberConsent ?? true; var selectedScops = model?.ScopesConsented ?? Enumerable.Empty <string>(); var vm = new ConsentViewModel() { ClientName = request.Client.ClientName ?? request.Client.ClientId, ClientLogoUrl = request.Client.LogoUri, ClientUrl = request.Client.ClientUri, RememberConsent = rememberConsent, IdentityScopes = request.ValidatedResources.Resources.IdentityResources.Select(i => CreateScopeViewModel(i, selectedScops.Contains(i.Name) || model == null)), }; var apiScopes = new List <ScopeViewModel>(); foreach (var parsedScope in request.ValidatedResources.ParsedScopes) { var apiScope = request.ValidatedResources.Resources.FindApiScope(parsedScope.ParsedName); if (apiScope != null) { var scopeVm = CreateScopeViewModel(parsedScope, apiScope, vm.ScopesConsented.Contains(parsedScope.RawValue) || model == null); apiScopes.Add(scopeVm); } } vm.ResourceScopes = apiScopes; return(vm); }
public async Task <IActionResult> Index(InputConsentViewModel viewModel) { //var model = await BuildConsentViewModel(returnUrl); return(View()); }
public async Task <ConsentViewModel> BuildConsentViewModelAsync(string returnUrl, InputConsentViewModel inputConsent = null) { // 通过 identityServerInteractionService 获取 authorization context 信息 var requestContext = await _identityServerInteractionService.GetAuthorizationContextAsync(returnUrl); if (requestContext == null) { return(null); } // 通过 clientStore 获取 client 信息 var client = await _clientStore.FindEnabledClientByIdAsync(requestContext.ClientId); if (client == null) { return(null); } // 通过 resourceStore 获取 apiResource 和 identityResource 信息 var resource = await _resourceStore.FindEnabledResourcesByScopeAsync(requestContext.ScopesRequested); if (resource == null) { return(null); } var consentViewModel = CreateConsentViewModel(requestContext, client, resource, inputConsent); //将 returnUrl 绑定到 consentViewModel对象上 consentViewModel.ReturnUrl = returnUrl; return(consentViewModel); }
public async Task <IActionResult> Index(string returnUrl, InputConsentViewModel vm) { var model = await _consentSvc.BuildConsentViewModel(returnUrl, vm); return(View(model)); }
private ConsentViewModel CreateConsentViewModel(Client client, Resources resources, InputConsentViewModel model) { var selectedScopes = model?.ScopesConsented ?? Enumerable.Empty <string>(); return(new ConsentViewModel { ClientName = client.ClientName, ClientLogoUrl = client.LogoUri, ClientUrl = client.ClientUri, RememberConsent = model?.RememberConsent ?? client.AllowRememberConsent, IdentityScopes = resources.IdentityResources.Select(i => CreateScopeViewModel(i, selectedScopes.Contains(i.Name))), ResourceScopes = resources.ApiResources.SelectMany(i => i.Scopes) .Select(i => CreateScopeViewModel(i, selectedScopes.Contains(i.Name))) }); }
private ConsentViewModel CreateConsentViewModel(AuthorizationRequest request, Client client, Resources resources, InputConsentViewModel model) { var selectedScopes = model?.ScopesConsented ?? Enumerable.Empty <string>(); var vm = new ConsentViewModel(); vm.ClientName = client.ClientName; vm.ClientLogoUrl = client.LogoUri; vm.ClientUrl = client.ClientUri; vm.RemeberConsent = model?.RemeberConsent ?? true; vm.IdentityScopes = resources.IdentityResources.Select(_identityResource => { return(new ScopeViewModel { Name = _identityResource.Name, DisplayName = _identityResource.DisplayName, Description = _identityResource.Description, Required = _identityResource.Required, Checked = selectedScopes.Contains(_identityResource.Name) || _identityResource.Required || model == null, Emphasize = _identityResource.Emphasize }); }); vm.ResourceScopes = resources.ApiResources.SelectMany(i => i.Scopes).Select(_scope => { return(new ScopeViewModel { Name = _scope.Name, DisplayName = _scope.DisplayName, Description = _scope.Description, Required = _scope.Required, Checked = selectedScopes.Contains(_scope.Name) || _scope.Required || model == null, Emphasize = _scope.Emphasize }); }); return(vm); }
private ConsentViewModel CreateConsentViewModel(AuthorizationRequest request, Client client, Resources resources, InputConsentViewModel model) { var selectedScopes = model?.ScopesConsented ?? Enumerable.Empty <string>(); var consentViewModel = new ConsentViewModel(); consentViewModel.ClientName = client.ClientName; consentViewModel.ClientLogoUrl = client.LogoUri; consentViewModel.ClientUrl = client.ClientUri; //consentViewModel.AllowRememberConsent = client.AllowRememberConsent; consentViewModel.RememberConsent = (model == null || model.RememberConsent); // client.AllowRememberConsent; consentViewModel.IdentityScopes = resources.IdentityResources.Select(i => CreateScopeViewModel(i, model == null || selectedScopes.Contains(i.Name))); consentViewModel.ResourceScopes = resources.ApiResources.SelectMany(a => a.Scopes).Select(s => CreateScopeViewModel(s, model == null || selectedScopes.Contains(s.Name))); return(consentViewModel); }