Esempio n. 1
0
 //Helper methods used by othere tests
 private LoginResponse LoginAs(string userName, string password = null, bool assertSuccess = true, string deviceToken = null)
 {
     password = password ?? Samples.BookStore.SampleData.SampleDataGenerator.DefaultPassword;
       var loginRq = new LoginRequest() { UserName = userName, Password = password , DeviceToken = deviceToken};
       var resp = SetupHelper.Client.ExecutePost<LoginRequest, LoginResponse>(loginRq, "api/login");
       Assert.IsTrue(resp != null, "Authentication failed.");
       if(resp.Status == LoginAttemptStatus.Success) {
     SetupHelper.Client.AddRequestHeader("Authorization", resp.AuthenticationToken);
     return resp;
       }
       if (assertSuccess)
     Assert.IsTrue(false, "Authentication failed, Status: " + resp.Status);
       return resp;
 }
Esempio n. 2
0
 public LoginResponse Login(LoginRequest request)
 {
     Context.ThrowIfNull(request, ClientFaultCodes.ContentMissing, "LoginRequest", "Content object missing in API request.");
       Context.WebContext.Flags |= WebCallFlags.Confidential;
       //Login using LoginService
       var loginResult = _loginService.Login(this.Context, request.UserName, request.Password, request.TenantId, request.DeviceToken);
       var login = loginResult.Login;
       switch(loginResult.Status) {
     case LoginAttemptStatus.PendingMultifactor:
       var processService = Context.App.GetService<ILoginProcessService>();
       var token = processService.GenerateProcessToken();
       var process = processService.StartProcess(loginResult.Login, LoginProcessType.MultiFactorLogin, token);
       return new LoginResponse() { Status = LoginAttemptStatus.PendingMultifactor, MultiFactorProcessToken = token };
     case LoginAttemptStatus.AccountInactive:
       // return AccountInactive only if login allows to disclose membership
       var reportStatus = login.Flags.IsSet(LoginFlags.DoNotConcealMembership) ? LoginAttemptStatus.AccountInactive : LoginAttemptStatus.Failed;
       return new LoginResponse() { Status = reportStatus };
     case LoginAttemptStatus.Failed:
     default:
       return new LoginResponse() { Status = loginResult.Status };
     case LoginAttemptStatus.Success:
       var displayName = Context.App.GetUserDispalyName(loginResult.User);
       return new LoginResponse() {
     Status = LoginAttemptStatus.Success, AuthenticationToken = loginResult.SessionToken,
     UserName = login.UserName,  UserDisplayName = displayName,
     UserId = login.UserId, AltUserId = login.AltUserId, LoginId = login.Id,
     PasswordExpiresDays = login.GetExpiresDays(), Actions = loginResult.Actions, LastLoggedInOn = loginResult.LastLoggedInOn
       };
       }//switch
 }