public static async Task<string> AuthenticateAsync(string username, string password) { Console.WriteLine("Authenticating user with username {0} and password {1}", username, password); var authRequest = new AuthenticateUserRequest(); authRequest["username"] = username; authRequest["password"] = password; var authResponse = await authRequest.ExecuteAsync(); ApiHelper.EnsureValidResponse(authResponse); return authResponse.Token; }
public async Task AuthenticateWithUsernamePasswordTestAsync() { // Create the user var user = await UserHelper.CreateNewUserAsync(); var authRequest = new AuthenticateUserRequest(); authRequest["username"] = user.Username; authRequest["password"] = user.Password; var authResponse = await authRequest.ExecuteAsync(); ApiHelper.EnsureValidResponse(authResponse); Assert.IsTrue(string.IsNullOrWhiteSpace(authResponse.Token) == false, "Auth token is not valid."); Assert.IsNotNull(authResponse.User, "Authenticated user is null."); Console.WriteLine("Logged in user id: {0}", authResponse.User.Id); Console.WriteLine("Session token: {0}", authResponse.Token); }