x
Developer

Getting "not authorized" error when trying to exchange code for access token

Hi all -

Hoping someone can help with this.

I can successfully generate the URL to prompt for permissions form.

However, after the user accepts, we are trying to exchange the code returned for a token.

However, when we attempt to use the code provided, we get an error response for the access token saying:


{"message"=>"Not Authorized", "type"=>"service.not_authorized"}

 

Any assistance is appreciated. Agian, this is AFTER the permission link has been clicked and approved.

Tags (1)
3,997 Views
Message 1 of 8
Report
7 REPLIES 7
Alumni

Hi! 

 

Sorry that you are having troubles, (and I hope your hoiday season was nice!) but I'll see if I can help. 

 

What is your application id? And which programming language are you using? It sounds like you might be malforming, or mixing up your request to the endpiont, so any code you could share, would be helpful as well! 

3,243 Views
Message 2 of 8
Report

Hi, I am also getting the error. 

 

{
    "message": "Not Authorized",
    "type": "service.not_authorized"
}

 

I get the code and redirect as I was supposed to, but when I try to send cliend_id, client_secret and code to https://connect.squareup.com/oauth2/token I am getting the error above. 

App id: sandbox-sq0idp-TZyrZ3dg61kqmEp0ZakxVQ

 

PHP is being used.

 

Cheers,

Alek

3,134 Views
Message 3 of 8
Report

I am also having the same problem. I am using the java oauth connect-examples code. 

App ID: sq0idp-udjQPpkVMEOa6QIiFf8Cpw

2,786 Views
Message 4 of 8
Report
Admin

Hello @vuusa2000! If you're still experiencing this issue please start a case with our API CS team and they'll be able to investigate this further. Thanks for your patience! 

️ Helen
Seller Community Manager

Did you find help in the Seller Community? Mark a Best Answer to help others.
2,774 Views
Message 5 of 8
Report

I'm also getting this error.

From php code, javascript code and their example wen page they have to test it

 

https://developer.squareup.com/explorer/square_2019-12-17/oauth-api/obtain-token


I follow the link, it returns me to a page with the code in the querystring,
I come here and put that code along with my id key and authorization_code for the type.

Press run request. and   error 401 

{
  "message": "Not Authorized",
  "type": "service.not_authorized"
}



1,860 Views
Message 6 of 8
Report
Square Community Moderator

Hi @werdemup,

 

I'd recommend contacting our API team with the link Helen provided in the comment above yours to take a closer look.

 

We don't have the API training here on the Community team to be able to assist with this directly. 

Ashley C
Community Moderator, Square
Sign in and click Mark as Best Answer if my reply answers your question.
1,845 Views
Message 7 of 8
Report

Check that you are using correct url endpoint. I have used "https://connect.squareup.com/oauth2/token" in sandbox, but should use "https://connect.squareupsandbox.com"

1,719 Views
Message 8 of 8
Report