# /api/v2/oauth/token Authentication problems

**URL:** <https://community.auth0.com/t/api-v2-oauth-token-authentication-problems/86698>\
**Category:** Get Help\
**Created:** [July 10, 2022, 1:30am UTC](https://community.auth0.com/t/api-v2-oauth-token-authentication-problems/86698 "2022-07-10T01:30:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rogeriobrum](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rogeriobrum/32/38668_2.png) [@rogeriobrum](https://community.auth0.com/u/rogeriobrum)\
**Post date:** [July 10, 2022, 1:30am UTC](https://community.auth0.com/t/api-v2-oauth-token-authentication-problems/86698/1 "2022-07-10T01:30:44Z")

</div>

Hello everyone.

I’m trying to integrate Auth0 with cypress on NextJS. For that I’m using a npm package called `cypress-nextjs-auth0`.

When I try to authenticate using that package I got an `invalid_grant` error. Digging deeper into the code I was able to catch the request that is being made to Auth0.

The url is https://.us.auth0.com/oauth/token and is accessed via POST.

The JSON data is:

```auto
{
  "audience": "<MY_AUDIENCE>", // got it from tenant settings > general
  "client_id": "<MY_CLIENT_ID>", // got it from my application, tried it as a regular web application or a machine to machine one
  "client_secret": "<MY_CLIENT_SECRET>", // got it from the same place as the previous one
  "scope": "openid profile email", // not sure if this is right
  "grant_type": "password",
  "username": "username@example.com",
  "password": "some_password"
}

```

To that I get the response:

```auto
{
	"error": "invalid_grant",
	"error_description": "Wrong email or password."
}

```

User and password are correct.

What am I missing here?

---

<div class="post-metadata">

**Author:** ![john.gateley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john.gateley/32/10879_2.png) [@john.gateley](https://community.auth0.com/u/john.gateley)\
**Post date:** [July 11, 2022, 1:46pm UTC](https://community.auth0.com/t/api-v2-oauth-token-authentication-problems/86698/2 "2022-07-11T13:46:01Z")

</div>

Hi @rogeriobrum

Why are you using ROPG (password grant)? You should probably be using Auth Code or Auth Code + PKCE.

I don’t see a connection specified in your JSON data. Check your app in the Auth0 dashboard and make sure it is enabled for the proper connection - and I think with ROPG you need a default connection.

Also check your tenant logs, they may provide more info.

Mostly though you probably do want to switch to Auth Code or Auth Code + PKCE

John

---

<div class="post-metadata">

**Author:** ![lihua.zhang](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lihua.zhang/32/39683_2.png) [@lihua.zhang](https://community.auth0.com/u/lihua.zhang)\
**Post date:** [July 11, 2022, 5:52pm UTC](https://community.auth0.com/t/api-v2-oauth-token-authentication-problems/86698/4 "2022-07-11T17:52:47Z")

</div>

Thank you @john.gateley for helping with this community topic.

Hi @rogeriobrum ,

Welcome to the Auth0 Community!

I found a Support ticket with the same query created today. Do you happen to know about the Auth0 Support Ticket? And could you please DM me the tenant so we can verify this? Thank you!

---

<div class="post-metadata">

**Author:** ![rogeriobrum](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rogeriobrum/32/38668_2.png) [@rogeriobrum](https://community.auth0.com/u/rogeriobrum)\
**Post date:** [July 11, 2022, 7:39pm UTC](https://community.auth0.com/t/api-v2-oauth-token-authentication-problems/86698/7 "2022-07-11T19:39:11Z")

</div>

I did choose the grant\_type password because it was what the the cypress-nextjs-auth0 docs instructed me to do.  
I’m a little lost on this. I don’t find Auth0 docs to be much friendly to be honest.

---

<div class="post-metadata">

**Author:** ![rogeriobrum](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rogeriobrum/32/38668_2.png) [@rogeriobrum](https://community.auth0.com/u/rogeriobrum)\
**Post date:** [July 11, 2022, 7:39pm UTC](https://community.auth0.com/t/api-v2-oauth-token-authentication-problems/86698/8 "2022-07-11T19:39:26Z")

</div>

Yes, it is the same.  
I’ll DM you.

---

<div class="post-metadata">

**Author:** ![john.gateley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john.gateley/32/10879_2.png) [@john.gateley](https://community.auth0.com/u/john.gateley)\
**Post date:** [July 12, 2022, 2:16pm UTC](https://community.auth0.com/t/api-v2-oauth-token-authentication-problems/86698/9 "2022-07-12T14:16:10Z")

</div>

Hi @rogeriobrum

Take a look at this page: [Which OAuth 2.0 Flow Should I Use?](https://auth0.com/docs/get-started/authentication-and-authorization-flow/which-oauth-2-0-flow-should-i-use)

It explains the different flows and when they are appropriate.

John

---

<div class="post-metadata">

**Author:** ![lihua.zhang](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lihua.zhang/32/39683_2.png) [@lihua.zhang](https://community.auth0.com/u/lihua.zhang)\
**Post date:** [July 12, 2022, 3:46pm UTC](https://community.auth0.com/t/api-v2-oauth-token-authentication-problems/86698/10 "2022-07-12T15:46:36Z")

</div>

@john.gateley Thank you again for contributing to this topic 🙏

@rogeriobrum ,

Thank you for confirming the Support ticket in the DM. As I mentioned, please continue working with the Support team. I will watch out for the updates on the Support ticket and post the solution once it’s solved.

---

<div class="post-metadata">

**Author:** ![lihua.zhang](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lihua.zhang/32/39683_2.png) [@lihua.zhang](https://community.auth0.com/u/lihua.zhang)\
**Post date:** [July 25, 2022, 5:39pm UTC](https://community.auth0.com/t/api-v2-oauth-token-authentication-problems/86698/11 "2022-07-25T17:39:04Z")

</div>

here is the summary of the solution:

The user does not exist in the connection you are trying to connect to hence getting the wrong username or password.

As a workaround, you can try going to the Connections tab in the application and selecting the connection.

To provide more information, the Resource Owner Password Flow uses /token endpoint directly. other flows that use /authorize you may as well use the connection parameter to force the connection you want to connect to (not in the flow you are using), in [the authentication API](https://auth0.com/docs/api/authentication) you can see the allowed parameters for the different flows.

---

<div class="post-metadata">

**Author:** ![lihua.zhang](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lihua.zhang/32/39683_2.png) [@lihua.zhang](https://community.auth0.com/u/lihua.zhang)\
**Post date:** [July 30, 2022, 3:00pm UTC](https://community.auth0.com/t/api-v2-oauth-token-authentication-problems/86698/12 "2022-07-30T15:00:29Z")

</div>

This topic was automatically closed after 4 days. New replies are no longer allowed.
