# Regarding Issue with generating authorization code for READER SDK

**URL:** <https://developer.squareup.com/forums/t/regarding-issue-with-generating-authorization-code-for-reader-sdk/11941>\
**Category:** Questions\
**Tags:** reader-sdk, oauth-api\
**Created:** [January 25, 2024, 8:28am UTC](https://developer.squareup.com/forums/t/regarding-issue-with-generating-authorization-code-for-reader-sdk/11941 "2024-01-25T08:28:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shubham1](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@Shubham1](https://developer.squareup.com/forums/u/Shubham1)\
**Post date:** [January 25, 2024, 8:28am UTC](https://developer.squareup.com/forums/t/regarding-issue-with-generating-authorization-code-for-reader-sdk/11941/1 "2024-01-25T08:28:05Z")

</div>

Hi,

First of all web are using a account as a marketplace for developer access. Where sellers are authorizing for mobile sdk token generate permssion using this api flow:

> **[OAuth API Overview](https://developer.squareup.com/docs/oauth-api/overview)**
>
> The OAuth API lets you request permissions from Square sellers to manage their resources and get access tokens to call Square APIs on their behalf.

After completing this flow we are getting access token for generation Mobile auth code for that seller. We are asking seller to provide their location id:

After that we are using this api:

[Build with the Mobile Authorization API](https://developer.squareup.com/docs/mobile-authz/build-with-mobile-authz)

by using received access token from oAuth and location id shared by seller.

Which is providing us mobile authorization code that we are using for authorize Reader sdk.

But when we are authorising with received mobile authorization code SDK throwing an error like attached below screenshot:

 ![WhatsApp Image 2024-01-15 at 10.31.19 PM](https://global.discourse-cdn.com/square/original/2X/f/f8891f921f1979c397f315da3c33f061c12585f6.jpeg)

So, please us know what’s we are doing wrong.

Here is some attached curl requests:

```auto
This url is for requesting oauth by seller. 
   "https://connect.squareup.com/oauth2/authorize?client_id=<Developer client id>&scope=PAYMENTS_WRITE_IN_PERSON&redirect_uri=redirect_url&code_challenge=<code_challenge>";

```

Then this one to get access token for generating mobile auth code for that seller:

```auto
curl https://connect.squareup.com/oauth2/token \
  -X POST \
  -H 'Square-Version: 2022-04-20' \
  -H 'Content-Type: application/json' \
  -d '{
    "client_id": "<YOUR_APPLICATION_ID>",
    "grant_type": "authorization_code",
    "redirect_uri": "<THE REDIRECT URL>",
    "code": "<THE_AUTHORIZATION_CODE_YOU_WERE_GIVEN>",
    "code_verifier":"<THE CODE_VERIFIER YOU CREATED>"
      }'

```

Which is returning output something like this:

```auto
{
    "access_token": "xxxxxxxx",
    "token_type": "bearer",
    "expires_at": "2024-02-14T16:54:02Z",
    "merchant_id": "yyyyyy",
    "refresh_token": "xxxxxxxxxxxxxxx",
    "short_lived": false,
    "refresh_token_expires_at": "2024-04-14T16:53:31Z"
}

```

Then hitting this api curl to generate mobile auth code:

```auto
curl https://connect.squareup.com/mobile/authorization-code \
  -X POST \
  -H 'Square-Version: 2024-01-18' \
  -H 'Authorization: Bearer {ACCESS_TOKEN}' \
  -H 'Content-Type: application/json' \
  -d '{
    "location_id": "{LOCATION ID}"
  }'

```

Which is returning output like below:

```auto
[authorization_code] => sq0acp-Yss2W_pagj9jsI8wCjzpcnsdHwgfyvIyxg97CzQiQO0
[expires_at] => 2024-01-15T17:55:31Z

```

Then when authorizing with this code we are getting above error screenshot shared.

Awaiting your solution.

Thanks

---

<div class="post-metadata">

**Author:** ![Square-Dev-AI](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/square-dev-ai/32/2513_2.png) [@Square-Dev-AI](https://developer.squareup.com/forums/u/Square-Dev-AI)\
**Post date:** [January 25, 2024, 8:28am UTC](https://developer.squareup.com/forums/t/regarding-issue-with-generating-authorization-code-for-reader-sdk/11941/2 "2024-01-25T08:28:37Z")

</div>

👋 I’m Square Dev AI, here to help answer your question!  
Based on the information you’ve provided, the following documentation will help answer your question:

> **[Build with the Mobile Authorization API](https://developer.squareup.com/docs/mobile-authz/build-with-mobile-authz)**
>
> Build with the Mobile Authorization API to request authorization tokens to initialize Square mobile solutions like the Reader SDK.

> **[Request a Mobile Authorization Code on the Command Line](https://developer.squareup.com/docs/mobile-authz/cookbook/mobile-code-with-curl)**
>
> Request authorization tokens with a command-line tool to initialize Square mobile solutions like the Reader SDK.

> **Additional Documentation**
>
> [Mobile Authorization API: How It Works](https://developer.squareup.com/docs/mobile-authz/how-it-works)  
> [Mobile Authorization API Overview](https://developer.squareup.com/docs/mobile-authz/what-it-does)  
> [OAuth Walkthrough: Test Authorization with Web Server](https://developer.squareup.com/docs/oauth-api/build-with-oauth)

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.  
Otherwise one of our Developer Advocates will provide additional assistance shortly.

---

<div class="post-metadata">

**Author:** ![Square-Dev-AI](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/square-dev-ai/32/2513_2.png) [@Square-Dev-AI](https://developer.squareup.com/forums/u/Square-Dev-AI)\
**Post date:** [January 26, 2024, 9:23pm UTC](https://developer.squareup.com/forums/t/regarding-issue-with-generating-authorization-code-for-reader-sdk/11941/3 "2024-01-26T21:23:12Z")

</div>

The error message you’re seeing typically indicates that the mobile authorization code you’re using has expired. Mobile authorization codes are short-lived and should be used immediately to authorize mobile solutions like the Reader SDK. If the code isn’t used immediately, it may expire and result in the error you’re seeing.

To resolve this, you should ensure that the mobile authorization code is used immediately after it’s generated. If the code has expired, you will need to generate a new one.

Also, please note that the Mobile Authorization API isn’t supported in the Square Sandbox. Make sure you’re using production credentials when making these API calls.

Lastly, ensure that the location ID you’re using is active and belongs to the same merchant that the access token is associated with.

If you continue to experience issues, please provide more details about the steps you’re taking and where exactly in the process the error occurs.

_This answer was reviewed by @josh-square._

---

<div class="post-metadata">

**Author:** ![Shubham1](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@Shubham1](https://developer.squareup.com/forums/u/Shubham1)\
**Post date:** [January 29, 2024, 12:02pm UTC](https://developer.squareup.com/forums/t/regarding-issue-with-generating-authorization-code-for-reader-sdk/11941/4 "2024-01-29T12:02:28Z")

</div>

Hi @josh-square ,  
Thanks for your response.

As we have checked we did test with Mobile Auth code, immediately(which even have 1 hours expiry time for new generated mobile auth code) after generating still we are getting error that authorize\_invalid\_code at app end during Authorization.

We followed below steps :

1. Redirect seller to connect with our app using PKCE flow. which returns code. ( `https://connect.squareup.com/oauth2/authorize?client_id=<CLIENT_ID>&scope=PAYMENTS_WRITE_IN_PERSON,MERCHANT_PROFILE_READ&redirect_uri=<REDIRECT_URI>&code_challenge=26c5a737267a6b63fd0d1b52b7e2601cd78194c5db3cfd22e26b1c7aca206057`
2. Then using that code we used the return code to generate oAuth access token

```auto

```

curl --location ‘[https://connect.squareup.com/oauth2/token](https://connect.squareup.com/oauth2/token)’   
–header ‘Square-Version: 2021-05-13’   
–header ‘Content-Type: application/json’   
–data ‘{  
“client\_id”: “\<CLIENT\_ID\>”,  
“code”: “`”,
“grant_type”: “authorization_code”,
“redirect_uri” : “<REDIRECT_URI>”,
“code_verifier” : “<CODE_VERIFIER>”
}’`

`
```auto

3. Then we used this generated access token to generate Mobile Auth Code, In which we pass first Location Id(which same on sellers square dashboard (https://squareup.com/dashboard/locations/LAJXDFV4WF19F) received from Locations API using seller access token , 

Getting Seller Locations:

curl --location 'https://connect.squareup.com/v2/locations' \
--header 'Square-Version: 2024-01-18' \
--header 'Authorization: Bearer <access token>' \
--header 'Content-Type: application/json'

Then generating: authorization-code

```
curl --location ‘https://connect.squareup.com/mobile/authorization-code’ 
–header ‘Square-Version: 2024-01-18’ 
–header ‘Authorization: Bearer {access_token}’ 
–header ‘Content-Type: application/json’ 
–data ‘{
“location_id”: “LAJXDFV4WF19F”
}’
```auto

which returns this output: 

```
{
“authorization_code”: “sq0acp- ******** ”,
“expires_at”: “2024-01-29T12:52:53Z”
}
```auto

This authorization_code we used for authorizing mobile SDK. 

But we are getting error: authorize_invalid_code
![Screenshot_20240129-172415|225x500](upload://1ozUfBlR9d410K1TYLyXCH9ow9s.png)

So, Please check and let me know what's wrong now. 

Awaiting response.

Thanks
````

---

<div class="post-metadata">

**Author:** ![josh-square](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@josh-square](https://developer.squareup.com/forums/u/josh-square)\
**Post date:** [January 30, 2024, 1:26am UTC](https://developer.squareup.com/forums/t/regarding-issue-with-generating-authorization-code-for-reader-sdk/11941/5 "2024-01-30T01:26:24Z")

</div>

Hi @Shubham1, it looks like there’s an issue with the formatting of your post, do you mind attaching those screenshots again? Thanks!

---

<div class="post-metadata">

**Author:** ![Shubham1](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@Shubham1](https://developer.squareup.com/forums/u/Shubham1)\
**Post date:** [January 30, 2024, 6:50am UTC](https://developer.squareup.com/forums/t/regarding-issue-with-generating-authorization-code-for-reader-sdk/11941/6 "2024-01-30T06:50:51Z")

</div>

![Screenshot_20240129-172415](https://global.discourse-cdn.com/square/original/2X/0/09c973d8e0042f24fe6a727c17eb8e520608e13a.png)
