# JWT invalid signature in Mobile + API (Swift + Django)

**URL:** <https://community.auth0.com/t/jwt-invalid-signature-in-mobile-api-swift-django/106960>\
**Category:** JWT.io\
**Tags:** django, swift, access-token, ios\
**Created:** [May 15, 2023, 8:35pm UTC](https://community.auth0.com/t/jwt-invalid-signature-in-mobile-api-swift-django/106960 "2023-05-15T20:35:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ferranconde](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ferranconde/32/47229_2.png) [@ferranconde](https://community.auth0.com/u/ferranconde)\
**Post date:** [May 15, 2023, 8:35pm UTC](https://community.auth0.com/t/jwt-invalid-signature-in-mobile-api-swift-django/106960/1 "2023-05-15T20:35:30Z")

</div>

Hello everyone,

I’m implementing an iOS application that needs to communicate with a Python/Django backend. For that, I am following the [Mobile + API architecture scenario](https://auth0.com/docs/get-started/architecture-scenarios/mobile-api). Instead of Android and Node.js, I am following the iOS Swift quickstart and the Django API tutorial.

The issue is that the access token I receive after logging in is invalid: I cannot decode it using any Python library, since the signature has “wrong crypto padding”.

In my Auth0 dashboard, I have a `Native` app and a custom API.  
My iOS app is the provided Auth0-SwiftUI example app. I log users into my app using the universal login flow.

```swift
func login() {
        let credentialsManager = CredentialsManager(authentication: Auth0.authentication())
        Auth0
            .webAuth()
            .audience(MY_API_AUDIENCE)
            .useEphemeralSession()
            .start { result in
                switch result {
                case .success(let credentials):
                  // credentials.accessToken is malformed

```

As you can see, I ensure I specify the audience matching my API to prevent receiving an opaque token back.  
I cannot decode the access token I receive using Python’s `jwt` package (I can decode the header and the payload separately, but not the full token). I am using my JWKS correctly to get the public key to decode the token with.  
When I paste it in [jwt.io](http://jwt.io), it does complain about “invalid signature” (but I think that’s expected?), but I can see the header and payload.  
The payload contains the following, among others:

```json
"iss": "<my Auth0 domain>",
  "aud": [
    "MY_API_AUDIENCE",
    "<my Auth0 domain>/userinfo"
  ],
  "scope": "openid profile email <other scopes configured in the Authorization Extension>",

```

What am I doing wrong? How can I get an access token that I can use to call my backend API?

Thank you!

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [May 15, 2023, 10:19pm UTC](https://community.auth0.com/t/jwt-invalid-signature-in-mobile-api-swift-django/106960/2 "2023-05-15T22:19:54Z")

</div>

Hi there @ferranconde welcome to the community!

Thanks for the detailed description - That’s very odd based on the information you’ve shared, it all looks good at a high level to me 🤔 Do you mind grabbing an example access token generated by your iOS app, throwing it into [jwt.io](http://jwt.io) and sharing a screenshot here (redacting any sensitive info)?

If you don’t mind sending me an actual jwt from a test user directly via DM that would be helpful as well 🙂

---

<div class="post-metadata">

**Author:** ![ferranconde](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ferranconde/32/47229_2.png) [@ferranconde](https://community.auth0.com/u/ferranconde)\
**Post date:** [May 16, 2023, 12:20pm UTC](https://community.auth0.com/t/jwt-invalid-signature-in-mobile-api-swift-django/106960/4 "2023-05-16T12:20:25Z")

</div>

Hi @ty.frith , thanks for the quick reply.  
I will send you a DM with an actual jwt.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [May 17, 2023, 6:25pm UTC](https://community.auth0.com/t/jwt-invalid-signature-in-mobile-api-swift-django/106960/5 "2023-05-17T18:25:14Z")

</div>

Following up here in order to share with the rest of community - The issue ended up being related to a truncated token value when copied from Xcode like so:

 ![Screenshot 2023-05-17 at 11.22.22 AM](https://global.discourse-cdn.com/auth0/original/3X/5/6/56d9e0944895c7ed64984cb993a11f219585d801.png)

There is no issue with Auth0.swift generating tokens, thanks for confirming @ferranconde ! 🚀

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [May 31, 2023, 6:26pm UTC](https://community.auth0.com/t/jwt-invalid-signature-in-mobile-api-swift-django/106960/6 "2023-05-31T18:26:09Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
