src/HarmonyHub/Client.cs
/// <summary>
/// Logs into Logitech endpoint and retrieves an "auth token"
/// </summary>
/// <param name="username">Username to authenticate with.</param>
/// <param name="password">Password to authenticate with.</param>
/// <returns>Logitech auth token.</returns>
Logs into Logitech endpoint and retrieves an "auth token"
Logs into Logitech endpoint and retrieves an " auth token "
private string LoginToLogitech(string username, string password)
        {
            const string logitechAuthUrl = "https://svcs.myharmony.com/CompositeSecurityServices/Security.svc/json/GetUserAuthToken";
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(logitechAuthUrl);
            httpWebRequest.ContentType = "text/json";
            httpWebRequest.Method = "POST";
            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                var json = JsonSerializer<GetUserAuthTokenRequest>.Serialize(new GetUserAuthTokenRequest { Email = username, Password = password });
                streamWriter.Write(json);
                streamWriter.Flush();
            }
            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            var responseStream = httpResponse.GetResponseStream();
            if (responseStream == null)
                return null;
            using (var streamReader = new StreamReader(responseStream))
            {
                var result = streamReader.ReadToEnd();
                var harmonyData = JsonSerializer<GetUserAuthTokenResultRootObject>.Deserialize(result);
                return harmonyData.GetUserAuthTokenResult?.UserAuthToken;
            }
        }
private string LoginToLogitech ( string username , string password ) { const string logitechAuthUrl = " " ; var httpWebRequest = ( HttpWebRequest ) WebRequest . Create ( logitechAuthUrl ) ; httpWebRequest . ContentType = " " ; httpWebRequest . Method = " " ; using ( var streamWriter = new StreamWriter ( httpWebRequest . GetRequestStream ( ) ) ) { var json = JsonSerializer < GetUserAuthTokenRequest > . Serialize ( new GetUserAuthTokenRequest { Email = username , Password = password } ) ; streamWriter . Write ( json ) ; streamWriter . Flush ( ) ; } var httpResponse = ( HttpWebResponse ) httpWebRequest . GetResponse ( ) ; var responseStream = httpResponse . GetResponseStream ( ) ; if ( responseStream == null ) return null ; using ( var streamReader = new StreamReader ( responseStream ) ) { var result = streamReader . ReadToEnd ( ) ; var harmonyData = JsonSerializer < GetUserAuthTokenResultRootObject > . Deserialize ( result ) ; return harmonyData . GetUserAuthTokenResult ? . UserAuthToken ; } }
Logs into Logitech endpoint and retrieves an "auth token"
Logs into Logitech endpoint and retrieves an " auth token "
Logitech auth token.
Logitech auth token .
username
string
Username to authenticate with.
Username to authenticate with .
password
string
Password to authenticate with.
Password to authenticate with .