Ejemplo n.º 1
0
 private void RenewAccessToken()
 {
     AdmAccessToken newAccessToken = HttpPost(DatamarketAccessUri, this.request);
     //swap the new token with old one
     //Note: the swap is thread unsafe
     this.token = newAccessToken;
     Trace.WriteLine(string.Format("Renewed token for user: {0} is: {1}", this.clientId, this.token.access_token));
 }
Ejemplo n.º 2
0
 public AdmAuthentication(string clientId, string clientSecret)
 {
     this.clientId = clientId;
     this.clientSecret = clientSecret;
     //If clientid or client secret has special characters, encode before sending request
     this.request = string.Format("grant_type=client_credentials&client_id={0}&client_secret={1}&scope=http://api.microsofttranslator.com", HttpUtility.UrlEncode(clientId), HttpUtility.UrlEncode(clientSecret));
     this.token = HttpPost(DatamarketAccessUri, this.request);
     //renew the token every specfied minutes
     accessTokenRenewer = new Timer(new TimerCallback(OnTokenExpiredCallback), this, TimeSpan.FromMinutes(RefreshTokenDuration), TimeSpan.FromMilliseconds(-1));
 }