0 Replies Latest reply on May 21, 2017 4:34 AM by poomanis87394962

    Echosign RestAPI Access Token Generation in C#

    poomanis87394962

      Hi All,

       

      I have download the Echosign Rest Client API and consume the same in my Asp.Net web application. Can you tell me, How to create Access Token? I have passed the required parameter to below method but Access token is null.

       

      /// <summary>

              /// Initialize EchosignREST without Access Token. Must call Authorize() after initialization to acquire Access Token.

              /// </summary>

              /// <param name="apiUrl">API url returned from the authorization request URL</param>

              /// <param name="clientId">Application/Client ID</param>

              /// <param name="secretId">Client Secret</param>

      public EchosignREST(string apiUrl, string clientId, string secretId)

              {

                  this.apiUrl = apiUrl;

                  this.clientId = clientId;

                  this.secretId = secretId;

       

                  client = new HttpClient();

                  client.BaseAddress = new Uri(apiUrl);

              }

       

      How to access below method without creating Access Token by above method?

       

      /// <summary>

              /// Obtain Access Token for the Echosign REST API (use only if you don't already have a Refresh Token, or if it is expired)

              /// </summary>

              /// <param name="authCode">Authorization code received from the authorization request</param>

              /// <param name="redirect_uri">Redirect URI matching the one specified in the authorization request</param>

              /// <returns></returns>

              public async Task Authorize(string authCode, string redirect_uri)

              {

                  using (HttpContent content = new FormUrlEncodedContent(new List<KeyValuePair<string, string>>

                  {

                      new KeyValuePair<string, string>("grant_type", "authorization_code"),

                      new KeyValuePair<string, string>("client_id", clientId),

                      new KeyValuePair<string, string>("client_secret", secretId),

                      new KeyValuePair<string, string>("code", authCode),

                      new KeyValuePair<string, string>("redirect_uri", redirect_uri)

                  }))

                  {

                      HttpResponseMessage result = await client.PostAsync("oauth/token", content).ConfigureAwait(false);

                      if (result.IsSuccessStatusCode)

                      {

                          string response = await result.Content.ReadAsStringAsync();

                          TokenResponse tokenObj = JsonConvert.DeserializeObject<TokenResponse>(response);

       

       

                          this.accessToken = tokenObj.access_token;

                          this.accessTokenExpires = tokenObj.expires_in;

                          this.refreshToken = tokenObj.refresh_token;

       

       

                          client.DefaultRequestHeaders.Remove("Access-Token");

                          client.DefaultRequestHeaders.Add("Access-Token", accessToken);

                      }

                      else

                      {

                          string response = await result.Content.ReadAsStringAsync().ConfigureAwait(false);

                          HandleError(result.StatusCode, response, true);

                      }

                  }

              }

      Thanks & Regards

      Poomani Sankaran