# How to Authorize Square Mobile Payments SDK via Backend and without using token in Frontend?

**URL:** <https://developer.squareup.com/forums/t/how-to-authorize-square-mobile-payments-sdk-via-backend-and-without-using-token-in-frontend/18978>\
**Category:** Questions\
**Tags:** payments-api\
**Created:** [September 30, 2024, 9:35pm UTC](https://developer.squareup.com/forums/t/how-to-authorize-square-mobile-payments-sdk-via-backend-and-without-using-token-in-frontend/18978 "2024-09-30T21:35:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![WilliamC](https://avatars.discourse-cdn.com/v4/letter/w/ce7236/32.png) [@WilliamC](https://developer.squareup.com/forums/u/WilliamC)\
**Post date:** [September 30, 2024, 9:35pm UTC](https://developer.squareup.com/forums/t/how-to-authorize-square-mobile-payments-sdk-via-backend-and-without-using-token-in-frontend/18978/1 "2024-09-30T21:35:30Z")

</div>

Problem Description:

I am currently using the Square Mobile Payments SDK, and the official documentation shows how to authorize the SDK directly by passing the `accessToken` and `locationID` from the frontend, as shown in the example below:

swift

```auto
import SquareMobilePaymentsSDK

class MyViewController: UIViewController {
    func authorizeMobilePaymentsSDK(accessToken: String, locationID: String) {
        guard MobilePaymentsSDK.shared.authorizationManager.state == .notAuthorized else {
            return
        }

        MobilePaymentsSDK.shared.authorizationManager.authorize(
           accessToken: accessToken,
            locationID: locationID) { error in
                if let authError = error {
                    // Handle auth error
                    print("error: \(authError.localizedDescription)")
                    return
                }

                print("Square Mobile Payments SDK successfully authorized.")
        }
    }
}

```

This method works but involves passing the `accessToken` directly in the frontend, which is not ideal for a production environment due to security concerns.

#### My Approach:

To improve security, my approach is as follows:

1. **Frontend** requests an authorization code from a Lambda function.
2. **BACK END** handles the actual authorization process using Square API and returns an `authorization code` to the frontend.
3. **Frontend** receives this `authorization code` and uses it with the Mobile Payments SDK to complete the authorization process, instead of passing the `accessToken` directly.

#### My Question:

In the official documentation, I couldn’t find any methods for authorizing the Mobile Payments SDK using an `authorization code` rather than the `accessToken`. I am looking for guidance on whether this is possible.

I would like to achieve the following workflow:

1. The frontend gets an `authorization code` from the backend .
2. The frontend uses this `authorization code` with the Mobile Payments SDK to complete the authorization.

**My specific questions are:**

- Does the Square Mobile Payments SDK support authorization using an `authorization code`?
- If so, which method or function should I call to complete this authorization?
- If not, is there any recommended best practice to secure the `accessToken` and avoid exposing it directly in the client-side code?

#### Thank You:

Any guidance or alternative solutions would be greatly appreciated. My goal is to securely authorize the SDK without exposing sensitive information like the `accessToken` to the client-side.

---

<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:** [September 30, 2024, 9:35pm UTC](https://developer.squareup.com/forums/t/how-to-authorize-square-mobile-payments-sdk-via-backend-and-without-using-token-in-frontend/18978/2 "2024-09-30T21:35:51Z")

</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:

> **[Mobile Authorization API: How It Works](https://developer.squareup.com/docs/mobile-authz/how-it-works)**
>
> Use the Mobile Authorization API to request authorization tokens to initialize Square mobile solutions like the Reader SDK.

> **[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.

> **Additional Documentation**
>
> [Mobile Authorization API](https://developer.squareup.com/docs/mobile-authz/what-it-does)  
> [Request a Mobile Authorization Code on the Command Line](https://developer.squareup.com/docs/mobile-authz/cookbook/mobile-code-with-curl)  
> [Receive Seller Authorization and Manage Seller OAuth Tokens](https://developer.squareup.com/docs/oauth-api/receive-and-manage-tokens)

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:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [September 30, 2024, 10:30pm UTC](https://developer.squareup.com/forums/t/how-to-authorize-square-mobile-payments-sdk-via-backend-and-without-using-token-in-frontend/18978/3 "2024-09-30T22:30:37Z")

</div>

The Mobile Payments SDK can only be authorized with an access token and `location_id`. An authorization can’t be used with the Mobile Payments SDK. 🙂

---

<div class="post-metadata">

**Author:** ![WilliamC](https://avatars.discourse-cdn.com/v4/letter/w/ce7236/32.png) [@WilliamC](https://developer.squareup.com/forums/u/WilliamC)\
**Post date:** [September 30, 2024, 11:01pm UTC](https://developer.squareup.com/forums/t/how-to-authorize-square-mobile-payments-sdk-via-backend-and-without-using-token-in-frontend/18978/4 "2024-09-30T23:01:44Z")

</div>

THX for your quick respond ,Bryan, I dont really feel comfortable to store TOKEN in the Frount End, what do you think ? can you share some advise ? [quote=“Bryan-Square, post:3, topic:18978, full:true”]  
The Mobile Payments SDK can only be authorized with an access token and `location_id`. An authorization can’t be used with the Mobile Payments SDK. 🙂  
[/quote]

😃
