# First party SPA using connectors and talking with a first party API

**URL:** <https://community.auth0.com/t/first-party-spa-using-connectors-and-talking-with-a-first-party-api/19935>\
**Category:** Get Help\
**Created:** [January 13, 2019, 6:19pm UTC](https://community.auth0.com/t/first-party-spa-using-connectors-and-talking-with-a-first-party-api/19935 "2019-01-13T18:19:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![brewtus](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/brewtus/32/10410_2.png) [@brewtus](https://community.auth0.com/u/brewtus)\
**Post date:** [January 13, 2019, 6:19pm UTC](https://community.auth0.com/t/first-party-spa-using-connectors-and-talking-with-a-first-party-api/19935/1 "2019-01-13T18:19:17Z")

</div>

**First a disclaimer and an apology:** I’ve done a bunch of reading over the last few hours in an attempt to grasp the concepts and best practices before asking my question: the quick start guides, the SPA & custom API guide, the difference between ID Token and Access Token, etc. I can’t seem to wrap my head around it. Sorry.

**Next, my goal:** I have a SPA. I want end-users to be able to authenticate using either a username and password (using Auth0’s provided username-password-authentication) or one of my two connectors (Google and Microsoft). I have an API that the SPA (and, theoretically, any other consumer) will use to get work done. This API should be able to assess that a **user** has the proper scopes to perform the actions.

**What I need help with:** I think I understand that when a user signs in in the SPA, they will be authenticating with Auth0 (for user-pass-auth) or the with Google or Microsoft. The SPA will get an ID Token and an Access Token. The access token’s audience is the SPA, correct? So how do I turn around and authenticate that user with my first-party API so that I can get an Access Token whose audience is the API so that calls can be made in order to do work?

---

<div class="post-metadata">

**Author:** ![charsleysa](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/charsleysa/32/9722_2.png) [@charsleysa](https://community.auth0.com/u/charsleysa)\
**Post date:** [January 14, 2019, 12:42am UTC](https://community.auth0.com/t/first-party-spa-using-connectors-and-talking-with-a-first-party-api/19935/2 "2019-01-14T00:42:47Z")

</div>

Hi @brewtus

The audience you specify will be your API and not your SPA.

The reason for this is when you make the authentication request to Auth0 you are pretty much saying “I want to authenticate the user so that this SPA (specified by the client\_id) can access this API (specified by the audience)”.

This is the reason why you can’t use id\_token for API’s since the id\_token is intended for you SPA and as such the audience is set to your SPA’s client\_id.

You would then send the access\_token received by the successful authentication to your API on every HTTPS request using the standard `Authorization` header with the `Bearer <access_token>` format.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![brewtus](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/brewtus/32/10410_2.png) [@brewtus](https://community.auth0.com/u/brewtus)\
**Post date:** [January 19, 2019, 3:28am UTC](https://community.auth0.com/t/first-party-spa-using-connectors-and-talking-with-a-first-party-api/19935/3 "2019-01-19T03:28:04Z")

</div>

So what does this mean for the SPA? If the user is at the SPA with a link to sign in in front of them, should that link direct them to `https://mytenant.auth0.com/authorize` with all the necessary things and with the audience set to my API audience and the response type set to `token id_token`?

---

<div class="post-metadata">

**Author:** ![charsleysa](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/charsleysa/32/9722_2.png) [@charsleysa](https://community.auth0.com/u/charsleysa)\
**Post date:** [January 19, 2019, 3:45am UTC](https://community.auth0.com/t/first-party-spa-using-connectors-and-talking-with-a-first-party-api/19935/4 "2019-01-19T03:45:12Z")

</div>

Hi @brewtus

Yes, that is essentially correct though I would recommend using the Auth0.js library to generate the URL and redirect the user on your SPA’s behalf.

The reasoning for letting the Auth0.js library handle it is that they keep the library up to date with the latest best practices and such, so that’s one less thing for you to worry about.

---

<div class="post-metadata">

**Author:** ![brewtus](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/brewtus/32/10410_2.png) [@brewtus](https://community.auth0.com/u/brewtus)\
**Post date:** [January 20, 2019, 7:26pm UTC](https://community.auth0.com/t/first-party-spa-using-connectors-and-talking-with-a-first-party-api/19935/5 "2019-01-20T19:26:12Z")

</div>

Right, yes. That makes sense. I was just curious about what’s happening under the hood there.

So even though the audience that I’m sending is for the API and the _access token_ that I receive will be for my API, the _ID token_ will be for the SPA?

---

<div class="post-metadata">

**Author:** ![charsleysa](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/charsleysa/32/9722_2.png) [@charsleysa](https://community.auth0.com/u/charsleysa)\
**Post date:** [January 21, 2019, 12:36am UTC](https://community.auth0.com/t/first-party-spa-using-connectors-and-talking-with-a-first-party-api/19935/6 "2019-01-21T00:36:59Z")

</div>

Yes, that is correct.

Just a note that the ID Token is only for the SPA.

Any requests to Auth0 API’s (such as the `/userinfo` endpoint) require the Access Token.

---

<div class="post-metadata">

**Author:** ![brewtus](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/brewtus/32/10410_2.png) [@brewtus](https://community.auth0.com/u/brewtus)\
**Post date:** [January 22, 2019, 3:44am UTC](https://community.auth0.com/t/first-party-spa-using-connectors-and-talking-with-a-first-party-api/19935/7 "2019-01-22T03:44:38Z")

</div>

That makes perfect sense.

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 22, 2019, 3:40pm UTC](https://community.auth0.com/t/first-party-spa-using-connectors-and-talking-with-a-first-party-api/19935/8 "2019-01-22T15:40:45Z")

</div>

Glad that you have figured it out!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [August 29, 2019, 9:12am UTC](https://community.auth0.com/t/first-party-spa-using-connectors-and-talking-with-a-first-party-api/19935/9 "2019-08-29T09:12:22Z")

</div>


