square / connect-csharp-sdk

C# client library for the Square Connect APIs
https://docs.connect.squareup.com/
Apache License 2.0
27 stars 25 forks source link

bad authorization header #119

Closed jmawebtech closed 5 years ago

jmawebtech commented 5 years ago

Hi,

Can you help with this error?

Here is my code:

    public SquareProvider(string merchantId, string applicationId, string applicationSecret, string accessToken)
    {
        Configuration.Default.AccessToken = accessToken;
        Configuration.Default.ApiKey.Add("Authorization", applicationSecret);
    }

    public RenewTokenResponse Authenticate()
    {
        RenewTokenResponse response = new RenewTokenResponse();

        try
        {
            SearchLocations();
        }
        catch(ApiException)
        {
            response = RenewToken();
            accessToken = response.AccessToken;
        }

        return response;
    }

    public RenewTokenResponse RenewToken()
    {
        OAuthApi apiInstance = new OAuthApi();
        RenewTokenRequest body = new RenewTokenRequest();

        RenewTokenResponse result = apiInstance.RenewTokenAsync(applicationId, body).Result;

        return result;

    }

POST https://connect.squareup.com/oauth2/clients/APP_ID/access-token/renew HTTP/1.1 Accept: application/json Authorization: APP_Secret User-Agent: Square-Connect-CSharp/2.20190508.0 Content-Type: application/json Host: connect.squareup.com Content-Length: 2 Accept-Encoding: gzip, deflate

{}

HTTP/1.1 400 Bad Request Access-Control-Allow-Headers: Content-Type, Authorization, Accept Access-Control-Allow-Origin: * Access-Control-Expose-Headers: Link Content-Type: application/json Vary: Origin, Accept-Encoding X-Content-Type-Options: nosniff X-Download-Options: noopen X-Frame-Options: DENY X-Permitted-Cross-Domain-Policies: none X-Request-Id: Cgh8A7zD5EEWhxABGBAiCQihyIiEnNDiAg X-Xss-Protection: 1; mode=block Date: Tue, 04 Jun 2019 16:12:48 GMT keep-alive: timeout=60 Strict-Transport-Security: max-age=631152000 content-length: 87

{ "message": "bad authorization header", "type": "bad_request.invalid_parameter" }