public async Task <UserAuthentication> AuthenticateAsync(IAuthProvider authProvider, CancellationToken ct, string state = null, string response_type = "code") { if (this.UserAuthentication != null) { try { this.UserAuthentication = await this.RefreshTokenAsync(ct); if (this.UserAuthentication != null) { return(this.UserAuthentication); } } catch (Exception ex) { Debug.WriteLine("Reauthentication through AuthenticateAsync failed: " + ex.ToString()); } } var uri = this.CreateRequestUri($"/oauth2/authorize?response_type={response_type}&client_id={CLIENT_ID}&redirect_uri={REDIRECT_URL}&state={state}"); var authorizationCode = await authProvider.AuthenticateAsync(uri, REDIRECT_URL, ct); if (authorizationCode != null) { this.UserAuthentication = await this.GetAccessTokenAsync(authorizationCode, ct); } else { this.UserAuthentication = null; } return(this.UserAuthentication); }
public async Task <ActionResult> Login(LoginViewModel viewModel, string redirectUrl) { bool success = await AuthProvider.AuthenticateAsync(viewModel.Email, viewModel.Password); if (success) { return(RedirectToRoute(redirectUrl)); } return(View(viewModel)); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (ModelState.IsValid) { bool result = await authProvider.AuthenticateAsync(model.UserName, model.Password); if (result) { return(Redirect(returnUrl ?? Url.Action("List", "Product")));//Url.Action("Index","Admin")); } else { ModelState.AddModelError("", "Nieprawidłowa nazwa użytkownika lub nieprawidłowe hasło"); return(View()); } } return(View()); }