# Why is email/password authentication failing on express-jwt

**URL:** <https://community.auth0.com/t/why-is-email-password-authentication-failing-on-express-jwt/61301>\
**Category:** Get Help\
**Tags:** express-jwt\
**Created:** [April 18, 2021, 2:22pm UTC](https://community.auth0.com/t/why-is-email-password-authentication-failing-on-express-jwt/61301 "2021-04-18T14:22:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrecasal](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/andrecasal/32/28659_2.png) [@andrecasal](https://community.auth0.com/u/andrecasal)\
**Post date:** [April 18, 2021, 2:22pm UTC](https://community.auth0.com/t/why-is-email-password-authentication-failing-on-express-jwt/61301/1 "2021-04-18T14:22:58Z")

</div>

Please include the following information in your post:

- **Which SDK this is regarding:** express-jwt
- **SDK Version:** 6.0.0
- **Platform Version:** Node 15.12.0
- **Code Snippets/Error Messages/Supporting Details/Screenshots:**  
 ![Screenshot 2021-04-18 at 15.16.41](https://global.discourse-cdn.com/auth0/original/3X/7/b/7b6d3eae49b33658e0b3b61a86015f28249b4bac.png)

# Gatsby client using ApolloClient

```
const httpLink = new HttpLink({ uri: process.env.API_DOMAIN, });

const authMiddleware = new ApolloLink((operation, forward) => {
	// Add the authorization to the headers
	operation.setContext({
		headers: {
			authorization: tokens.accessToken,
		}
	});

	return forward(operation);
});

const client = new ApolloClient({
	cache: new InMemoryCache(),
	link: concat(authMiddleware, httpLink),
});

client.query({
		query: gql`
			query eventQuery {
				events {
					_id
					title
					description
					date
				}
			}
		`}
	).then(result => console.log(result));

```

# Express server

index.js

```
const checkJwt = jwt({
    	// Dynamically provide a signing key based on the [Key ID](https://tools.ietf.org/html/rfc7515#section-4.1.4) header parameter ("kid") and the signing keys provided by the JWKS endpoint.
    	secret: jwksRsa.expressJwtSecret({
    		cache: true,
    		rateLimit: true,
    		jwksRequestsPerMinute: 5,
    		jwksUri: `https://${process.env.AUTH0_DOMAIN}/.well-known/jwks.json`
    	}),
    	// Validate the audience and the issuer.
    	audience: process.env.AUTH0_AUDIENCE,
    	issuer: `https://${process.env.AUTH0_DOMAIN}/`,
    	algorithms: ['RS256'],
    	getToken: function fromHeaderOrQuerystring(req) {
    		if (req.headers.authorization) {
    			return req.headers.authorization;
    		}
    		return null;
    	}
    });

app.use(
	'/graphql',
	checkJwt,
	graphqlHTTP({
		schema,
		rootValue: resolvers,
		context,
	}),
);

```

The client logged in using email and password. I’m sending the authorization token on the HTTP header. What else does the client need to send over to express-jwt to pass authentication?

The server is replying with 401 Unauthorized. How can I figure out the reason for this? Is debugging and running the code step by step the only way or does express-jwt provide some way to figure out the reason for failure? Logs maybe?

Cheers,  
André Casal

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 19, 2021, 1:18pm UTC](https://community.auth0.com/t/why-is-email-password-authentication-failing-on-express-jwt/61301/3 "2021-04-19T13:18:05Z")

</div>

Hi @andrecasal,

Looking at your screenshot, it looks like the `authorization` request header might be an opaque token instead of a JWT. Your app will receive an opaque token from Auth0 when a registered API is not specified as the audience in the authentication request. This opaque token is used for your Auth0 tenant’s `/userinfo` endpoint.

In order to get a JWT as the Access Token that your API can decode and use for authorization, you’ll need to:

1. Register your API from your Auth0 dashboard: [Register APIs](https://auth0.com/docs/get-started/set-up-apis)
2. Use the API identifier as the audience in the `Auth0Provider`:

```auto
ReactDOM.render(
  <Auth0Provider
    domain={config.domain}
    clientId={config.clientId}
    audience={config.audience} // <- add audience
    redirectUri={window.location.origin}
    onRedirectCallback={onRedirectCallback}
    useCookiesForTransactions={true}
  >
    <App />
  </Auth0Provider>,
  document.getElementById("root")
);

```

> **[Access Tokens](https://auth0.com/docs/secure/tokens/access-tokens)**
>
> Describes how access tokens are used in token-based authentication to allow an application to access an API after a user successfully authenticates and authorizes access.

---

<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:** [June 25, 2021, 1:01pm UTC](https://community.auth0.com/t/why-is-email-password-authentication-failing-on-express-jwt/61301/4 "2021-06-25T13:01:18Z")

</div>

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