public static AuthenticationToken Login(string username, string password)
{
Guard.NotNullOrEmpty(username, "username");
Guard.NotNullOrEmpty(password, "password");
Cookie cookie;
CookieCollection cookies;
Log.InfoFormat("fetching auth token from {0} for user {1}", LoginUri, username);
cookies = FetchLoginResponseCookies(username, password);
if((cookie = cookies[AuthCookieName]) == null)
{
Log.ErrorFormat("failed to fetch the auth token as no cookie named {0} was found" +
" in the response to the login request, assuming the credentials have been rejected",
AuthCookieName);
throw Guard.LiveAuthenticationService_CredentialsRejected();
}
Log.InfoFormat("fetched auth token {0}", cookie.Value);
return new AuthenticationToken(cookie.Value);
}