public async Task <IActionResult> AutheticateWithExternalIdProvider([FromBody] TCMClientRequest request) { dynamic inputData = request.Data; UserCredentials userCredentials = JsonConvert.DeserializeObject(inputData.ToString(), typeof(UserCredentials)); if (userCredentials == null) { _logger.Debug(GetType(), "UserCredentials are null"); throw new UnauthorizedAccessException(); } if (userCredentials.UserName == null) { _logger.Debug(GetType(), "Username is null"); throw new UnauthorizedAccessException(); } if (userCredentials.Password == null) { _logger.Debug(GetType(), "Password is null"); throw new UnauthorizedAccessException(); } bool isAuthenticated = _authenticate.Authenticate(userCredentials); var result = CreateUserResponse(userCredentials.UserName, isAuthenticated, new List <string>()); return(Ok(result)); }
public void AuthenticationShouldSucceed() { const string testBaseUri = "https://127.0.0.1"; const string expectedRequestUrl = testBaseUri + "/v15/access_tokens"; const string testClientId = "1a2b3c4d5e6f7g8h9i0j"; const string testMerchantUsername = "******"; const string testMerchantPassword = "******"; string expectedRequestbody = string.Format("{{\"access_token\": {{" + "\"api_key\": \"{0}\"" + ",\"username\": \"{1}\"" + ",\"password\": \"{2}\"" + "}}}}", testClientId, testMerchantUsername, testMerchantPassword); // This response format does not matter for this test. RestResponse expectedResponse = new RestResponse { StatusCode = HttpStatusCode.OK, }; IAuthenticate auth = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <IAuthenticate, AccessTokenRequest>( expectedResponse, expectedRequestbody, expectedAccessToken: null, expectedRequestUrl: expectedRequestUrl, environmentToUse: new LevelUpEnvironment(testBaseUri)); var token = auth.Authenticate(testClientId, testMerchantUsername, testMerchantPassword); }
static UserAccessTokenHolder() { IAuthenticate auth = GetSandboxedLevelUpModule <IAuthenticate>(); var token = auth.Authenticate(LevelUpTestConfiguration.Current.ClientId, LevelUpTestConfiguration.Current.ConsumerUsername, LevelUpTestConfiguration.Current.ConsumerPassword); SandboxedLevelUpUserAccessToken = token.Token; }
private bool IsValidToken(Guid token) { if (token == Guid.Empty) { return(false); } return(authenticator.Authenticate(token)); }
public IActionResult Post([FromBody] ApplicationUser authParam) { var authorizedUser = _auth.Authenticate(authParam.UserName, authParam.PasswordHash); if (authorizedUser == null) { return(BadRequest(new { message = "Username or password is incorrect" })); } return(Ok(authorizedUser)); }
public IActionResult Authenticate([FromBody] Login loginParam) { var token = _authService.Authenticate(loginParam.Username, loginParam.Password); if (token == null) { return(BadRequest(new { message = "Username or password is incorrect" })); } return(Ok(token)); }
public void AuthenticationShouldFailForErrorCode404NotFound() { const string testClientId = "1212whatsinthestew34noonesreallysure"; const string testMerchantUsername = "******"; const string testMerchantPassword = "******"; RestResponse expected = new RestResponse { StatusCode = HttpStatusCode.NotFound }; IAuthenticate auth = ClientModuleUnitTestingUtilities.GetMockedLevelUpModule <IAuthenticate>(expected); // Should throw exception for non-200 [OK] response auth.Authenticate(testClientId, testMerchantUsername, testMerchantPassword); }
public async Task <MobileServiceUser> LoginAsync() { IAuthenticate auth = DependencyService.Get <IAuthenticate>(); MobileServiceUser user = await auth.Authenticate(_client, MobileServiceAuthenticationProvider.Facebook); if (user == null) { Device.BeginInvokeOnMainThread(async() => { await Application.Current.MainPage.DisplayAlert("Ops!", "Problema no Login", "Ok"); }); } return(user); }
/// <summary> /// Performs the Authenticate(...) call to retrieve the access token that will be required for most of the /// subsequent requests you make to the LevelUp platform. /// </summary> private static string Authenticate(string merchantUserName, string merchantPassword, string apiKey) { try { IAuthenticate authenticator = LevelUpClientFactory.Create <IAuthenticate>(LuIdentifier, LuEnvironment); AccessToken tokenObj = authenticator.Authenticate(apiKey, merchantUserName, merchantPassword); return(tokenObj.Token); } catch (LevelUpApiException ex) { Console.WriteLine(string.Format("There was an error authenticating your user. Are the credentials " + "correct? {0}{0}Exception Details: {1}", Environment.NewLine, ex.Message)); return(null); } }
public async Task <IActionResult> Login(LoginViewModel model) { var result = await _authenticate.Authenticate(model.Email, model.Password); if (result) { if (string.IsNullOrEmpty(model.ReturnUrl)) { return(RedirectToAction("Index", "Home")); } return(RedirectToAction(model.ReturnUrl)); } else { ModelState.AddModelError(string.Empty, "Invalid login attempt. (password must be strong)"); return(View(model)); } }
public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { if (_authenticator.Authenticate(model.Username.ToLower(), model.Password)) { var user = _userRepository.Authenticate(model.Username.ToLower(), model.Password); Session.Add("UserData", user); FormsAuthentication.SetAuthCookie(model.Username, false); if (Request.Params.Count > 0 && Request.Params["ReturnUrl"] != null) { return(Redirect(Request.Params["ReturnUrl"])); } return(user.IsAdmin ? RedirectToAction("List") : RedirectToAction("Index", "Home")); } ModelState.AddModelError("", "Nombre de Usuario o Contraseña incorrectos"); } return(View()); }
public ActionResult Index(AuthenticationModel userDetails) { if (ModelState.IsValid) { IAuthenticate authenticationService = AuthenticationFactory.getAuthService(); bool authenticated = authenticationService.Authenticate(userDetails.Username, userDetails.Password); if (authenticated) { FormsAuthentication.SetAuthCookie(userDetails.Username, false); // Forward User to Application Home Page return(RedirectToAction("Index", "Home")); } } // Forward user to Not Authenticated Alert page return(View("NotAuthenticated")); }
public void AuthenticationShouldSucceedForCode200OK() { const int expectedUserId = 54321; const int expectedmerchantId = 32225; RestResponse expectedResponse = new RestResponse { StatusCode = HttpStatusCode.OK, Content = "{\"access_token\":" + "{\"merchant_id\":" + expectedmerchantId + ",\"token\":\"5564290-ee38925c6de8f4fd945e1606b232296f52f805563fb882fed1c6bq465dc367\"" + // this is not a real token ",\"user_id\":" + expectedUserId + "}}" }; IAuthenticate iAuth = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <IAuthenticate>(expectedResponse); var token = iAuth.Authenticate("This doesn't matter", "This has no bearing", "This can be whatever you want"); Assert.IsNotNull(token, "The deserialization of this successful authentication response should have succeeded"); Assert.AreEqual(token.MerchantId, expectedmerchantId); Assert.AreEqual(token.UserId, expectedUserId); }
public void Authenticate_Success() { Assert.IsTrue(authService.Authenticate(CorrectUserName, CorrectPassword)); }
public bool Authenticate(string username, string password) { return(_authenticator.Authenticate(username, password)); }