Unable to register the client

Hi,

I just created a new project and scaffolded my Db but when I “npm start” and try to see my dashboard, it is unable to authenticate me.

I have the following logs:

POST /forest/authentication 400 67 - 144.622 ms
[forest] :deciduous_tree::deciduous_tree::deciduous_tree: Unable to register the client

{
  "configuration": {
    "authorization_endpoint": "https://api.forestadmin.com/oidc/auth",
    "device_authorization_endpoint": "https://api.forestadmin.com/oidc/device/auth",
    "claims_parameter_supported": false,
    "claims_supported": [
      "sub",
      "email",
      "sid",
      "auth_time",
      "iss"
    ],
    "code_challenge_methods_supported": [
      "S256"
    ],
    "end_session_endpoint": "https://api.forestadmin.com/oidc/session/end",
    "grant_types_supported": [
      "authorization_code",
      "urn:ietf:params:oauth:grant-type:device_code"
    ],
    "id_token_signing_alg_values_supported": [
      "HS256",
      "RS256"
    ],
    "issuer": "https://api.forestadmin.com",
    "jwks_uri": "https://api.forestadmin.com/oidc/jwks",
    "registration_endpoint": "https://api.forestadmin.com/oidc/reg",
    "response_modes_supported": [
      "query"
    ],
    "response_types_supported": [
      "code",
      "none"
    ],
    "scopes_supported": [
      "openid",
      "email",
      "profile"
    ],
    "subject_types_supported": [
      "public"
    ],
    "token_endpoint_auth_methods_supported": [
      "none"
    ],
    "token_endpoint_auth_signing_alg_values_supported": [],
    "token_endpoint": "https://api.forestadmin.com/oidc/token",
    "request_object_signing_alg_values_supported": [
      "HS256",
      "RS256"
    ],
    "request_parameter_supported": false,
    "request_uri_parameter_supported": true,
    "require_request_uri_registration": true,
    "claim_types_supported": [
      "normal"
    ]
  },
  "registration": {
    "redirect_uris": [
      "http://localhost:3310/forest/authentication/callback"
    ],
    "token_endpoint_auth_method": "none"
  },
  "error": {
    "error": "expected 201 Created with body but no body was returned"
  }
}

I tried to set up a new AUTH token but it’s still the same.

Any idea?

Here are my packages versions:

"dependencies": {
    "body-parser": "1.19.0",
    "chalk": "~1.1.3",
    "cookie-parser": "1.4.4",
    "cors": "2.8.5",
    "debug": "~4.0.1",
    "dotenv": "~6.1.0",
    "express": "~4.17.1",
    "express-jwt": "6.0.0",
    "forest-express-sequelize": "^7.0.0",
    "morgan": "1.9.1",
    "require-all": "^3.0.0",
    "sequelize": "~5.15.1",
    "pg": "~8.2.2"
  }

Hello & welcome on our community forum @Simon_BRAMI1,

Can you share with me the failed query from the chrome development console in the networks tab?

Also, what is the name of the associated project?

Kind regards,
Louis

http://localhost:3310/forest/authentication
This request fails with 400 error.

Request Headers:

  1. Accept:
    2./*
  2. Accept-Encoding:
    gzip, deflate, br
  3. Accept-Language:
    fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7
  4. Connection:
    keep-alive
  5. Content-Length:
    23
  6. Content-Type:
    application/json; charset=utf-8
  7. Host:
    localhost:3310
  8. Origin:
    https://app.forestadmin.com
  9. sec-ch-ua:
    " Not;A Brand";v=“99”, “Google Chrome”;v=“91”, “Chromium”;v=“91”
  10. sec-ch-ua-mobile:
    ?0
  11. Sec-Fetch-Dest:
    empty
  12. Sec-Fetch-Mode:
    cors
  13. Sec-Fetch-Site:
    cross-site
  14. User-Agent:
    Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36

The associated project name is “Imok”

Thanks for your answer,

What is your APPLICATION_URL defined in your .env file? And also what is the content of the response from the request that failed?

APPLICATION_URL=http://localhost:3310

The response is the following:

{"error":"expected 201 Created with body but no body was returned"}

Thanks!

Thanks,

what are the last 5 digits of your ENV_SECRET from your .env file? And also can you share with me the body of the request that failed? :slight_smile:

The last 5 digits are: bce9f

The body of the request POST http://localhost:3310/forest/authentication

{"renderingId":"94937"}

:raised_hands:

Everything seems good on that side :slight_smile:

Have you setup a FOREST_CLIENT_ID in your .env file ? If so could you try to remove it an launch the authentication flow again?

Let me know if it helps,

Nop I didn’t I’m just trying to run the project locally. :slightly_frowning_face:

Have you been able to connect once? Did you finalize all the onboarding steps so that you had access to your project? :slight_smile:

I wasn’t able on this project, I have another project running on the v6 that works great and is running on production.
Before creating this new project I updated the lumber-cli and just followed the onboarding which perfectly scaffolded my DB and setup the codebase. And then the issue comes with the authentication…

Could that issue come from a dependency? Have you ever seen this error before?

I have never seen this before, however I can see that there is no authorization headers in the request sent from your backend which should explain the root of your issue.

Could you try to set the version of sequelize to 7.11.3

And just to be sure that everything is ok, could you please share with me your app.js file ?

Do you mean forest-express-sequelize? Last version of sequelize is 6.6.2

my app.js:

const express = require('express');
const requireAll = require('require-all');
const path = require('path');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const cors = require('cors');
const jwt = require('express-jwt');
const morgan = require('morgan');
const {
  errorHandler,
  ensureAuthenticated,
  PUBLIC_ROUTES,
} = require('forest-express-sequelize');

const app = express();

let allowedOrigins = [/\.forestadmin\.com$/, /localhost:\d{4}$/];

if (process.env.CORS_ORIGINS) {
  allowedOrigins = allowedOrigins.concat(process.env.CORS_ORIGINS.split(','));
}

const corsConfig = {
  origin: allowedOrigins,
  maxAge: 86400, // NOTICE: 1 day
  credentials: true,
};

app.use(morgan('tiny'));
app.use('/forest/authentication', cors({
  ...corsConfig,
  // The null origin is sent by browsers for redirected AJAX calls
  // we need to support this in authentication routes because OIDC
  // redirects to the callback route
  origin: corsConfig.origin.concat('null')
}));
app.use(cors(corsConfig));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use(jwt({
  secret: process.env.FOREST_AUTH_SECRET,
  credentialsRequired: false,
  algorithms: ['HS256'],
}));

app.use('/forest', (request, response, next) => {
  if (PUBLIC_ROUTES.includes(request.url)) {
    return next();
  }
  return ensureAuthenticated(request, response, next);
});

requireAll({
  dirname: path.join(__dirname, 'routes'),
  recursive: true,
  resolve: (Module) => app.use('/forest', Module),
});

requireAll({
  dirname: path.join(__dirname, 'middlewares'),
  recursive: true,
  resolve: (Module) => Module(app),
});

app.use(errorHandler());

module.exports = app;

Apparently, it works when I run my backend inside the docker container. This is not very convenient for me and I don’t understand what could cause this error outside of the container… Any idea?

It seems like the error message comes from openid-clien package.

I tried to clean npm cache and to set forest-express-sequelize to 7.11.3 but it has no effect.

I also recreated a test project but I keep getting the very same error.

All right, thanks for the update. Looking at your app.js file, everything looks right.

Looking at your project I think there is one error at the launch of your server that could be the culprit of such a situation. Can you tell me if there is any error logs on your server launch?

There is no error at launch, it’s just telling me that my server is running on port 3310, and the URL of my projects… The only error I have is the one I told you about when I try to access the dashboard and log in.

Do you have any snippets that could help me get more logs info?

By the way, my Node version is 14.1.0 and I know the docker container run a 10.X version.

Update: I tried to use the same Node version as the docker container: 10.24.1 and now it works :grinning_face_with_smiling_eyes:

Could you tell me a recent stable version of Node that works with FA?

SOLUTION: Run away from Node 14.1.0

1 Like

Well done! :clap:t2:

I personally use Node 14 for my projects and I have no particular problems with the launches. Maybe there was an incompatibility with the docker container set up. :confused: