private async Task <IActionResult> HandleImplicitGrantAsync(AuthorizationRequestModel model) { var command = new ImplicitGrantCommand { ClientId = model.ClientId, ScopeNames = model.Scope.Split(' '), RedirectUri = model.RedirectUri }; if (User.Identity.IsAuthenticated) { command.UserName = User.Identity.Name; } var result = await _sagaBus.InvokeAsync <ImplicitGrantCommand, OAuth20Result>(command); var context = _dataProtector.Protect(result.SagaId.ToString()); switch (result.State) { case OAuth20State.RequireSignIn: return(View("SignIn", new OAuthSignInModel { ProtectedOAuthContext = context })); case OAuth20State.RequirePermissionGrant: return(PermissionGrantView(result)); case OAuth20State.Finished: return(ImplictRedirect(result)); default: return(BadRequest()); } }
public async Task <IActionResult> Post([FromBody] ClientCreationDto dto) { var cmd = new CreateClientCommand { DisplayName = dto.DisplayName, RedirectUri = dto.RedirectUri }; var result = await _sagaBus.InvokeAsync <CreateClientCommand, ClientCreationResult>(cmd); if (result.Succeed) { var url = Url.Action(nameof(GetById), new { id = result.Id }); return(Created(url, null)); } return(StatusCode(412, result.Message)); }
public async Task <IActionResult> Post([FromBody] UserCreationDto dto) { var cmd = new CreateUserCommand { UserName = dto.UserName, Password = dto.Password }; var result = await _sagaBus.InvokeAsync <CreateUserCommand, UserCreationResult>(cmd); if (result.Succeed) { return(Created(Url.Action(nameof(GetById), new { id = result.UserId }), null)); } // currently, the only reason for failure is that a user of the same username exists. return(StatusCode(412, result.Message)); }
public async Task <IActionResult> Post([FromBody] ScopeCreationDto dto) { var cmd = new CreateScopeCommand { ClaimTypes = dto.ClaimTypes, Description = dto.Description, DisplayName = dto.DisplayName, ScopeName = dto.ScopeName }; var result = await _sagaBus.InvokeAsync <CreateScopeCommand, ScopeCreationResult>(cmd); if (result.Succeed) { return(Created(Url.Action(nameof(GetById), new { id = result.Id }), null)); } return(StatusCode(412, result.Message)); }
public async Task <IActionResult> SignIn([FromForm] SignInViewModel model) { var command = new PasswordAuthenticateCommand { UserName = model.UserName, Password = model.Password }; var authResult = await _sagaBus.InvokeAsync <PasswordAuthenticateCommand, AuthenticationResult>(command); if (!authResult.IsCredentialVaild) { ModelState.AddModelError(nameof(SignInViewModel.UserName), "Invaild user name"); ModelState.AddModelError(nameof(SignInViewModel.Password), "Or invaild password"); return(View("SignIn")); } await _signinService.CookieSignInAsync(AuthenticationSchemes.PortalCookie, authResult.User, model.RememberMe); return(Redirect(model.ReturnUrl)); }