# Authorization Code Flow with PKCE - Using express backend 404

**URL:** <https://community.auth0.com/t/authorization-code-flow-with-pkce-using-express-backend-404/78447>\
**Category:** Get Help\
**Tags:** electron, pkce, api\
**Created:** [February 17, 2022, 3:26am UTC](https://community.auth0.com/t/authorization-code-flow-with-pkce-using-express-backend-404/78447 "2022-02-17T03:26:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ibrahimsam96](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ibrahimsam96/32/35279_2.png) [@ibrahimsam96](https://community.auth0.com/u/ibrahimsam96)\
**Post date:** [February 17, 2022, 3:26am UTC](https://community.auth0.com/t/authorization-code-flow-with-pkce-using-express-backend-404/78447/1 "2022-02-17T03:26:24Z")

</div>

Express app running on [http://localhost:6001](http://localhost:6001) receiving requests from electron application on [http://localhost:5000](http://localhost:5000).

Authentication process:

**Authorization Code Flow with PKCE** - Authorizing the user(native app) and receive the authorization code in the url callback.

Decode it and then use it in the `POST /oauth/token` .

However, I’m receiving 404 error `"Request failed with status code 400"` when I call the `GET /authorize` endpoint.

```auto
const express = require("express");
const cors = require("cors");
import * as crypto from 'crypto';
import { nanoid } from 'nanoid'
import axios from 'axios';

const bodyParser = require ('body-parser');
const app = express();
var port = 6001;

app.use(cors());
app.use(bodyParser());
app.listen(port, () => console.log(`Example app listening on port ${port}!`));

app.get("/authorize", async (req: any, res: any, next:any) => {
  // Creates verifier 
  function base64URLEncode(str: Buffer) {
    return str.toString('base64')
      .replace(/\+/g, '-')
      .replace(/\//g, '_')
      .replace(/=/g, '');
  }
  var verifier = base64URLEncode(crypto.randomBytes(32));
  // Generate a code_challenge
  function sha256(buffer: string) {
    return crypto.createHash('sha256').update(buffer).digest();
  }
  var challenge = base64URLEncode(sha256(verifier));

  var nonce = nanoid();

  await axios.get(`https://dev-49v8whrc.us.auth0.com/authorize?response_type=code&
        client_id=----------------------&
        prompt=none&
        connection=Username-Password-Authentication&
        redirect_uri=http://localhost:6001/authorize&
        nonce=${nonce}&
        code_challenge=${challenge}&
        code_challenge_method=S256`).then((authCode: any) => res.send(authCode) ).catch((err) => res.send(err))

});

```

---

<div class="post-metadata">

**Author:** ![SaqibHussain](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/saqibhussain/32/42924_2.png) [@SaqibHussain](https://community.auth0.com/u/SaqibHussain)\
**Post date:** [February 17, 2022, 8:27am UTC](https://community.auth0.com/t/authorization-code-flow-with-pkce-using-express-backend-404/78447/2 "2022-02-17T08:27:42Z")

</div>

Hi @ibrahimsam96

Welcome to Auth0 Community. It’s great to have you on board.

It sounds like there’ll be an issue with the request that you’re making if you’re getting a 400. If you have a native app I’m assuming we cannot review the browser dev tools to have a look at the request that’s being sent? Maybe you can put some logging in to the backend code, analyse the `/authorize` request that’s being sent and ensure it looks something like this along with the correct parameters [https://auth0.com/docs/get-started/authentication-and-authorization-flow/add-login-using-the-authorization-code-flow-with-pkce#authorization-url-example](https://auth0.com/docs/get-started/authentication-and-authorization-flow/add-login-using-the-authorization-code-flow-with-pkce#authorization-url-example)

It might also be worth taking the request that you’re making and send it across via a curl command to help troubleshoot the issue.

Feel free to let us know if you still have issues with this.  
Regards.

---

<div class="post-metadata">

**Author:** ![ibrahimsam96](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ibrahimsam96/32/35279_2.png) [@ibrahimsam96](https://community.auth0.com/u/ibrahimsam96)\
**Post date:** [February 17, 2022, 5:36pm UTC](https://community.auth0.com/t/authorization-code-flow-with-pkce-using-express-backend-404/78447/3 "2022-02-17T17:36:52Z")

</div>

Hey Saqib!

**EDIT** : **I think I’m using the /authorize endpoint incorrectly. As noted in doc it should redirect back from an IdP and so i’m using the Username-Password-Authentication as a connection.** I will get back to this when I do the Google and Microsoft logins, Thanks for looking into this!

---

<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:** [February 18, 2022, 10:28am UTC](https://community.auth0.com/t/authorization-code-flow-with-pkce-using-express-backend-404/78447/4 "2022-02-18T10:28:02Z")

</div>

Sure let us know if you have other questions down the road!

---

<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:** [March 5, 2022, 10:28am UTC](https://community.auth0.com/t/authorization-code-flow-with-pkce-using-express-backend-404/78447/5 "2022-03-05T10:28:31Z")

</div>

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