public API_User Login(string submittedName, string submittedPass) { var credentials = new { username = submittedName, password = submittedPass }; RestRequest request = new RestRequest(LOGIN_URL); request.AddJsonBody(credentials); IRestResponse <API_User> response = client.Post <API_User>(request); user = response.Data; client.Authenticator = new JwtAuthenticator(user.Token); //IRestResponse<API_User> response = null; if (response.ResponseStatus != ResponseStatus.Completed) { throw new NoResponseException("An error occurred communicating with the server."); } else if (!response.IsSuccessful) { if (!string.IsNullOrWhiteSpace(response.Data.Message)) { throw new NonSuccessException("An error message was received: " + response.Data.Message); } else { throw new NonSuccessException("An error response was received from the server. The status code is " + (int)response.StatusCode); } } else { user.Token = response.Data.Token; return(response.Data); } }
public void Logout() { user = new API_User(); client.Authenticator = null; }