# SwiftUI app native login and API call

**URL:** <https://community.auth0.com/t/swiftui-app-native-login-and-api-call/114111>\
**Category:** Get Help\
**Tags:** apis, application\
**Created:** [August 21, 2023, 2:07pm UTC](https://community.auth0.com/t/swiftui-app-native-login-and-api-call/114111 "2023-08-21T14:07:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbbrehm](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@mbbrehm](https://community.auth0.com/u/mbbrehm)\
**Post date:** [August 21, 2023, 2:07pm UTC](https://community.auth0.com/t/swiftui-app-native-login-and-api-call/114111/1 "2023-08-21T14:07:02Z")

</div>

I am having a SwiftUI app which uses the authentication to a Native App in auth0, which works fine. Now I want to call an API, also protected by auth0 and the audience would be different. How could I retrieve an accessToken for the new audience given the fact, that I already have one from the App login. A similar topic was discussed here, but never answered [SwiftUI with Auth0 login app calling another API also protected by Auth0](https://community.auth0.com/t/swiftui-with-auth0-login-app-calling-another-api-also-protected-by-auth0/94761)

---

<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:** [August 22, 2023, 11:38pm UTC](https://community.auth0.com/t/swiftui-app-native-login-and-api-call/114111/3 "2023-08-22T23:38:25Z")

</div>

Hello @mbbrehm welcome to the community!

Are you using [Auth0.swift](https://github.com/auth0/Auth0.swift) or another SDK?

---

<div class="post-metadata">

**Author:** ![mbbrehm](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@mbbrehm](https://community.auth0.com/u/mbbrehm)\
**Post date:** [August 23, 2023, 12:22am UTC](https://community.auth0.com/t/swiftui-app-native-login-and-api-call/114111/4 "2023-08-23T00:22:56Z")

</div>

Yes, using Auth0.swift SDK… right now using AWS API Gateway fronting the API’s with a customer authorizer validating the JWT token and I am getting an error about “invalid audience”. Maybe I should just change the audience I am checking to the Native application audience.

---

<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:** [August 23, 2023, 12:39am UTC](https://community.auth0.com/t/swiftui-app-native-login-and-api-call/114111/5 "2023-08-23T00:39:55Z")

</div>

Thanks for confirming!

Is the API you’re calling already [registered in Auth0](https://auth0.com/docs/get-started/auth0-overview/set-up-apis)? If so, that’s the `audience` you’ll want to use when configuring `Auth0.webAuth()`

---

<div class="post-metadata">

**Author:** ![mbbrehm](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@mbbrehm](https://community.auth0.com/u/mbbrehm)\
**Post date:** [August 23, 2023, 12:51am UTC](https://community.auth0.com/t/swiftui-app-native-login-and-api-call/114111/6 "2023-08-23T00:51:03Z")

</div>

In the auth0 configuration I followed the tutorials for setting up a login to my Native iOS app and for this I have created an native application under Applications \> Applications (this has a clientID) and this where I get my token for, when signing into my iOS app. Further I got a customer API configured under Applications \> APIs, which has the audience of my API Gateway URL, following the tutorial there. Now I don’t want to have a second authentication done to call this API, but just use the token given through the initial user login.

---

<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:** [August 31, 2023, 7:03pm UTC](https://community.auth0.com/t/swiftui-app-native-login-and-api-call/114111/7 "2023-08-31T19:03:40Z")

</div>

Hey there @mbbrehm sorry for the delay here.

> [@mbbrehm](#):
>
> Now I don’t want to have a second authentication done to call this API, but just use the token given through the initial user login.

If the access token you received has the audience of your API, then that is the token you will want to use against it. Depending on your API there are many libraries you can use that verify access tokens:

> **[JWT.IO - JSON Web Tokens Libraries](https://jwt.io/libraries)**
>
> Find an overview of libraries that help you work with JSON Web Tokens in your favorite language.

---

<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:** [September 14, 2023, 7:03pm UTC](https://community.auth0.com/t/swiftui-app-native-login-and-api-call/114111/8 "2023-09-14T19:03:47Z")

</div>

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