AK.F1.Timing.Live.LiveAuthenticationService.Login C# (CSharp) Method

Login() public static method

Logs into the live-timing service using the specified credentials.
/// Thrown when or is /// . /// /// Thrown when or is empty. /// /// Thrown when an IO error occurs fetching the authentication token. /// /// Thrown when the supplied credentials have been rejected by the live-timing site. ///
public static Login ( string username, string password ) : AuthenticationToken
username string The user's F1 live-timing username.
password string The user's F1 live-timing password.
return AuthenticationToken
        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);
        }