# How to give Auth0Client an access token retrieved from to authenticate application

**URL:** <https://community.auth0.com/t/how-to-give-auth0client-an-access-token-retrieved-from-to-authenticate-application/96762>\
**Category:** Get Help\
**Tags:** apis, application\
**Created:** [December 19, 2022, 9:49pm UTC](https://community.auth0.com/t/how-to-give-auth0client-an-access-token-retrieved-from-to-authenticate-application/96762 "2022-12-19T21:49:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cjohnson](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cjohnson/32/39450_2.png) [@cjohnson](https://community.auth0.com/u/cjohnson)\
**Post date:** [December 19, 2022, 9:49pm UTC](https://community.auth0.com/t/how-to-give-auth0client-an-access-token-retrieved-from-to-authenticate-application/96762/1 "2022-12-19T21:49:05Z")

</div>

I am using `@auth0/auth0-spa-js` in my Vue 2 application, with Cypress. I have authentication working using `createAuth0Client`. However, I want to use programmatic authentication in Cypress to prevent running a UI-traversing login command every time we run a test, which would make our specs take minutes longer equaling to many, many minutes for a single command for all our suites.

I’ve got a request to Auth0 using a username and password successfully returning an access token, but I don’t know how and I can’t figure out from all Auth0’s documentation, specifically [Auth Spa JS](https://auth0.github.io/auth0-spa-js/modules.html), to pass that access\_token to my auth0 plugin within Vue to authenticate my test user.

I really don’t want to refactor parts of my application to think it’s authenticated if a token exists while the environment is testing.

---

<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:** [December 19, 2022, 10:00pm UTC](https://community.auth0.com/t/how-to-give-auth0client-an-access-token-retrieved-from-to-authenticate-application/96762/2 "2022-12-19T22:00:13Z")

</div>

Hello @cjohnson welcome to the community!

> [@cjohnson](#):
>
> I’ve got a request to Auth0 using a username and password successfully returning an access token, but I don’t know how and I can’t figure out from all Auth0’s documentation, specifically [Auth Spa JS](https://auth0.github.io/auth0-spa-js/modules.html), to pass that access\_token to my auth0 plugin within Vue to authenticate my test user.

Have you had a chance to check out the following blogpost? It’s a bit out of date but may still apply in your use case.

> **[End-to-End Testing with Cypress and Auth0](https://auth0.com/blog/end-to-end-testing-with-cypress-and-auth0/)**
>
> Learn how to programmatically authenticate against Auth0 in your Cypress tests in a manner that adheres to both Cypress and Auth0 best pr...

---

<div class="post-metadata">

**Author:** ![cjohnson](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cjohnson/32/39450_2.png) [@cjohnson](https://community.auth0.com/u/cjohnson)\
**Post date:** [December 20, 2022, 2:14pm UTC](https://community.auth0.com/t/how-to-give-auth0client-an-access-token-retrieved-from-to-authenticate-application/96762/4 "2022-12-20T14:14:43Z")

</div>

Yes, I’ve been over this a few times, but the example repo it uses is using auth-js, which I believe is what’s under the hood of auth-spa-js. I am really trying to avoid refactoring my auth0 integration on the FE as it took a LOT of work and refactoring of other pieces of our app to get it working.

I used this post to do most of the Cypress command refactoring and my code closely matches what’s recommended in this post.

I do know my application fails at this portion of the login tests in the post:

```auto
const callbackUrl = ...
cy.visit(callbackUrl, ...

```

I don’t have anything looking for those url parameters in my auth0Client plugin as it only recommends looking for `state` and `code`.

---

<div class="post-metadata">

**Author:** ![cjohnson](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cjohnson/32/39450_2.png) [@cjohnson](https://community.auth0.com/u/cjohnson)\
**Post date:** [December 20, 2022, 2:25pm UTC](https://community.auth0.com/t/how-to-give-auth0client-an-access-token-retrieved-from-to-authenticate-application/96762/5 "2022-12-20T14:25:38Z")

</div>

I can also see that even in the auth-spa-js package, it doesn’t really matter what you pass as parameters in a callback URL because `handleRedirectCallback` only looks for `state, code, error, error_description`.

My question → is there a way to pass an auth token to the `auth-spa-js` package to tell it to use the token to authenticate the user or do I need to swap to a different auth0 JS package?

---

<div class="post-metadata">

**Author:** ![cjohnson](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cjohnson/32/39450_2.png) [@cjohnson](https://community.auth0.com/u/cjohnson)\
**Post date:** [December 20, 2022, 2:34pm UTC](https://community.auth0.com/t/how-to-give-auth0client-an-access-token-retrieved-from-to-authenticate-application/96762/6 "2022-12-20T14:34:04Z")

</div>

I think my solution is to use auth.js instead of auth-spa-js, as it supplies a `webAuth.login()` function, which allows a username/password login. I can call this function inside of Cypress.

---

<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:** [December 24, 2022, 12:30am UTC](https://community.auth0.com/t/how-to-give-auth0client-an-access-token-retrieved-from-to-authenticate-application/96762/7 "2022-12-24T00:30:12Z")

</div>

Hey @cjohnson I apologize for the delayed response on this one - Thanks for following here with your solution, I’m sure it will help others in the future 🙏

---

<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:** [January 7, 2023, 12:31am UTC](https://community.auth0.com/t/how-to-give-auth0client-an-access-token-retrieved-from-to-authenticate-application/96762/8 "2023-01-07T00:31:04Z")

</div>

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