Your [One example of authorize requests:] looks fine but your call of [await oauthInstance.obtainToken] is very differ from your [One example of authorize requests:].
I am not very sure of your call of await oauthInstance.obtainToken() because I am not sure if you got correct [code] by calling JSON.stringfy(code-from-Square). [code] must be available from your callback or OAuthRedirect page so you don’t have to call JSON.stringfy() again. In javascript you could use <%=Session[“code”] %> where Session[“code”] is set as in your page by context.Request.QueryString[“code”];
Here is how I get the [code] from ‘callback url page / OAuthRedirect pgae’ in ASP.net.
ObtainTokenRequest body = new ObtainTokenRequest.Builder(
this.applicationId,
this.applicationSecret,
“authorization_code”)
.Code(authorizationCode) <====== This is the [code].
.Scopes(bodyScopes)
.Build();
//bodyScopes = List of strings. Authorized scopes for merchant. You are missing this.
IOAuthApi oAuthApi = client.OAuthApi;
Task t = oAuthApi.ObtainTokenAsync(body); //or (ObtainToken())
Your ObtainToken() method is missing ‘Scopes’ List of string, such as {“DEVICE_CREDENTIAL_MANAGEMENT”, “MERCHANT_PROFILE_READ”, “PAYMENTS_WRITE_ADDITIONAL_RECIPIENTS”, “PAYMENTS_WRITE”, “PAYMENTS_READ”}.
Refer to API Reference.
Let me know if you have resolved this problem or not. I am a developer also. Always welcome more knowledge, and want to know more.
Hi Bryan, it’s successful because I changed the call-back URL to my old backend.
My issue happens when I’m setting up a new backend for my application.
Everything is good with the old backend, compared those projects but couldn’t figure out what I’m missing for the new one.