Ejemplo n.º 1
0
        /// <summary>
        /// The user renews access token and refresh token
        /// </summary>
        /// <exception cref="ManualTransmissionClient.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="renewTokenRequest"></param>
        /// <returns>Task of ApiResponse (AccessTokenResponse)</returns>
        public async System.Threading.Tasks.Task <ApiResponse <AccessTokenResponse> > RenewTokenAsyncWithHttpInfo(RenewTokenRequest renewTokenRequest)
        {
            // verify the required parameter 'renewTokenRequest' is set
            if (renewTokenRequest == null)
            {
                throw new ApiException(400, "Missing required parameter 'renewTokenRequest' when calling UserApi->RenewToken");
            }

            var    localVarPath         = "/login/refreshToken";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new Dictionary <String, String>();
            var    localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json"
            };
            String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json"
            };
            String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (renewTokenRequest != null && renewTokenRequest.GetType() != typeof(byte[]))
            {
                localVarPostBody = Configuration.ApiClient.Serialize(renewTokenRequest); // http body (model) parameter
            }
            else
            {
                localVarPostBody = renewTokenRequest; // byte array
            }


            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await Configuration.ApiClient.CallApiAsync(localVarPath,
                                                                                                       Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                       localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("RenewToken", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <AccessTokenResponse>(localVarStatusCode,
                                                         localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                                         (AccessTokenResponse)Configuration.ApiClient.Deserialize(localVarResponse, typeof(AccessTokenResponse))));
        }
        /// <summary>
        /// RenewToken
        /// </summary>
        /// <remarks>
        /// OAuth access tokens besides your application's personal access token expire after 30 days. Use this endpoint to renew an expired token. If you provide a token that isn't expired, this endpoint does not extend its lifetime.
        /// You cannot renew an access token that has been expired for more than 15 days.Instead, the associated merchant must complete the OAuth flow from the beginning.
        /// </remarks>
        /// <exception cref="T:SquareConnectApiClient.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="authorization">Important: The Authorization header you provide to this endpoint must have the following format: Authorization: Client APPLICATION_SECRET. Replace APPLICATION_SECRET with your application's secret, available from the application dashboard.</param>
        /// <param name="clientId">Your application's ID, available from the application dashboard.</param>
        /// <param name="body">&gt;An object containing the fields to POST for the request.\n\nSee the corresponding object definition for field details.</param>
        /// <returns>Task of ApiResponse (RenewTokenResponse)</returns>
        public async Task <ApiResponse <RenewTokenResponse> > RenewTokenAsyncWithHttpInfo(string authorization, string clientId, RenewTokenRequest body)
        {
            // verify the required parameter 'authorization' is set
            if (authorization == null)
            {
                throw new ApiException(400, "Missing required parameter 'authorization' when calling RenewToken");
            }
            // verify the required parameter 'clientId' is set
            if (clientId == null)
            {
                throw new ApiException(400, "Missing required parameter 'clientId' when calling RenewToken");
            }
            // verify the required parameter 'body' is set
            if (body == null)
            {
                throw new ApiException(400, "Missing required parameter 'body' when calling RenewToken");
            }


            var localVarPath = "/oauth2/clients/{client_id}/access-token/renew";

            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new Dictionary <String, String>();
            var    localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json"
            };
            String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json"
            };
            String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            // set "format" to json by default
            // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
            localVarPathParams.Add("format", "json");
            if (clientId != null)
            {
                localVarPathParams.Add("client_id", Configuration.ApiClient.ParameterToString(clientId));                   // path parameter
            }
            if (authorization != null)
            {
                localVarHeaderParams.Add("Authorization", Configuration.ApiClient.ParameterToString(authorization));                        // header parameter
            }
            if (body.GetType() != typeof(byte[]))
            {
                localVarPostBody = Configuration.ApiClient.Serialize(body); // http body (model) parameter
            }
            else
            {
                localVarPostBody = body; // byte array
            }



            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await Configuration.ApiClient.CallApiAsync(localVarPath,
                                                                                                       Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                       localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (localVarStatusCode >= 400)
            {
                throw new ApiException(localVarStatusCode, "Error calling Renew Token: " + localVarResponse.Content, localVarResponse.Content);
            }
            else if (localVarStatusCode == 0)
            {
                throw new ApiException(localVarStatusCode, "Error calling Renew Token: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage);
            }

            return(new ApiResponse <RenewTokenResponse>(localVarStatusCode,
                                                        localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                                        (RenewTokenResponse)Configuration.ApiClient.Deserialize(localVarResponse, typeof(RenewTokenResponse))));
        }