public Response Authenticate(string email, string password)
{
RestRequest request = new RestRequest("_oauth2/token", Method.POST);
request.AddParameter("client_id", ClientId);
if (!String.IsNullOrEmpty(email))
{
Email = email;
request.AddParameter("username", email);
}
if (!String.IsNullOrEmpty(password))
request.AddParameter("password", password);
request.AddParameter("grant_type", "password");
//clear old access token, we don't want access token in this request
AccessToken = null;
this.Authenticator = null;
if (String.IsNullOrEmpty(ClientSecret))
throw new Exception("Client secret cannot be blank");
request.AddParameter("client_secret", ClientSecret);
Response response = Execute(request);
JObject responseObject = response.JObject;
AccessToken = (string)responseObject["access_token"];
if (responseObject["refresh_token"]!=null)
{
RefreshToken = (string)responseObject["refresh_token"];
}
if (CustomDomain==null && responseObject["systems"] != null)
{
JArray Systems = (JArray)responseObject["systems"];
if (Systems.Count > 0)
{
this.BaseUrl = "https://" + Systems[0]["host_name"];
}
}
return response;
}