Login Key Samples

Visit Glance Login Key Check to view an HTML page with a form to generate and test login keys.

The page may be saved and used locally since the key generation is carried out in the browser-side Javascript, and the page does not make server requests. To see working code that generates a Login Key, please refer to the Javascript source.

Typically, key generation will be done by server-side code to protect the API Key.

public static string GenerateLoginKey(int partnerId, string partnerUserId,
                                      int expirationSeconds, string apikey)
{
    const int ver        = 1;

    DateTime expires     = DateTime.Now.AddSeconds(expirationSeconds);
    DateTime epoch       = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
    int     expiration   = Convert.ToInt32((expires.ToUniversalTime() - epoch).TotalSeconds);

    string message       = partnerId.ToString() + partnerUserId.ToString() + ver.ToString()
                                                 + expiration.ToString();
    var    encoding      = new System.Text.UTF8Encoding();
    var    hmac          = new System.Security.Cryptography.HMACSHA256(encoding.GetBytes(apikey));

    string hash          = Convert.ToBase64String(hmac.ComputeHash(encoding.GetBytes(message)));

    hash = hash.Substring(0, 43).Replace('+', '-').Replace('/', '_');   // base64url no padding

    string loginkey      = '$' + ver.ToString() + '$' + expiration.ToString() + '$' + hash;
    return loginkey;
}

By continuing to use the site, you agree to the use of cookies. Learn More