public AdmAuthentication(string i_ClientId, string i_ClientSecret)
        {
            this.m_ClientId = i_ClientId;
            this.m_ClientSecret = i_ClientSecret;

            // If clientid or client secret has special characters, encode before sending request
            this.m_Request = string.Format(
                "grant_type=client_credentials&client_id={0}&client_secret={1}&scope=http://api.microsofttranslator.com",
                HttpUtility.UrlEncode(i_ClientId),
                HttpUtility.UrlEncode(i_ClientSecret));
            this.m_Token = httpPost(DatamarketAccessUri, this.m_Request);

            // renew the token every specfied minutes
            m_AccessTokenRenewer = new Timer(OnTokenExpiredCallback, this, TimeSpan.FromMinutes(k_RefreshTokenDuration), TimeSpan.FromMilliseconds(-1));
        }
Exemple #2
0
        public AdmAuthentication(string i_ClientId, string i_ClientSecret)
        {
            this.m_ClientId     = i_ClientId;
            this.m_ClientSecret = i_ClientSecret;

            // If clientid or client secret has special characters, encode before sending request
            this.m_Request = string.Format(
                "grant_type=client_credentials&client_id={0}&client_secret={1}&scope=http://api.microsofttranslator.com",
                HttpUtility.UrlEncode(i_ClientId),
                HttpUtility.UrlEncode(i_ClientSecret));
            this.m_Token = httpPost(DatamarketAccessUri, this.m_Request);

            // renew the token every specfied minutes
            m_AccessTokenRenewer = new Timer(OnTokenExpiredCallback, this, TimeSpan.FromMinutes(k_RefreshTokenDuration), TimeSpan.FromMilliseconds(-1));
        }
 private void RenewAccessToken()
 {
     // swap the new token with old one
     // Note: the swap is thread unsafe
     this.m_Token = httpPost(DatamarketAccessUri, this.m_Request);
     Trace.WriteLine(string.Format("Renewed token for user: {0} is: {1}", this.m_ClientId, this.m_Token.access_token));
 }