Post-login redirect-with-actions doesn't work, please tell me how to execute this correctly

With reference to this, we are implementing an implementation that redirects to another server at login and performs additional login processing.
I was able to pass user information and redirect with api.redirect.sendUserTo,
When I redirect to Auth0 Application again with https: // YOUR_DOMAIN / continue? State = THE_ORIGINAL_STATE, I get an Unauthorized error with Request failed with status code 401.

YOUR_DOMAIN → Domain automatically generated by Auth0 applications
THE_ORIGINAL_STATE → value of state parameter automatically assigned when redirecting api.redirect.sendUserTo

I tried both the GET and POST methods, but the redirection didn’t work.

Is there anything wrong with it, and I would like to know what to do in order for the redirection to take place and authentication to complete successfully.
Also, shouldn’t I return any response when redirecting to my server by api.redirect.sendUserTo, or should I redirect at https: // YOUR_DOMAIN / continue without worrying about it?

Hi @endo,

Welcome to the Community!

Can you post the entire error? There should be a more detailed message that will help us understand why the request is unauthorized.

thanks to reply, dan!

entire error is below.

{
  "message":"Request failed with status code 401",
  "name":"Error",
  "stack":"
    Error: Request failed with status code 401
    at createError (/var/task/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/var/task/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/var/task/node_modules/axios/lib/adapters/http.js:260:11)
    at IncomingMessage.emit (events.js:388:22)
    at endReadableNT (internal/streams/readable.js:1336:12)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
  ",
  "config":{
    "url":"https://my-app.jp.auth0.com/continue",
    "method":"post",
    "data":"{
      "isSuccess":false,
      "token":"${JWT token}",
      "state":"hKFo2SBXZkJzeWlha0YwMk1YNGROVDF5Mk9neC1GZXF1ZjVNNKFuqHJlZGlyZWN0o3RpZNkgMkw4cS1ra2QtcjFnczAtRjJtWm0tc3pELXh4NEQ2REGjY2lk2SBoTXJURXloWFJQN1dLZ3puYllsbUU3elUyVFkzdEZ1NQ",
      "headers":{
        "Accept":"application/json, text/plain, */*",
        "Content-Type":"application/json",
        "x-hasura-admin-secret":"${hasura secret}",
        "User-Agent":"axios/0.21.1",
        "Content-Length":687
      },
      "params":{
        "state":"hKFo2SBXZkJzeWlha0YwMk1YNGROVDF5Mk9neC1GZXF1ZjVNNKFuqHJlZGlyZWN0o3RpZNkgMkw4cS1ra2QtcjFnczAtRjJtWm0tc3pELXh4NEQ2REGjY2lk2SBoTXJURXloWFJQN1dLZ3puYllsbUU3elUyVFkzdEZ1NQ"
      },
      "transformRequest":[null],
      "transformResponse":[null],
      "timeout":0,
      "xsrfCookieName":"XSRF-TOKEN",
      "xsrfHeaderName":"X-XSRF-TOKEN",
      "maxContentLength":-1,
      "maxBodyLength":-1
    }
  }
}

@endo,

Can you please also post the code you use to resume authentication (the redirect to the /continue endpoint)?

HI.
I have the same 401 error
Here is my Node server code:

import { Get, Query } from 'tsoa';
import axios from 'axios';

@Get('/stats')
public async stats(@Query() state: string, @Query() data: any) {

    const auth0Url = 'https://my-domain.us.auth0.com/continue?state=';

    try {
      const url = encodeURI(auth0Url + state);
      await axios(url);
    } catch (err) {
      console.log(err);
    }
    managementBL.storeLogin(data);
}

and this is error:

Error: Request failed with status code 401
    at createError (/node_modules/.pnpm/axios@0.21.0/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/node_modules/.pnpm/axios@0.21.0/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/node_modules/.pnpm/axios@0.21.0/node_modules/axios/lib/adapters/http.js:244:11)
    at IncomingMessage.emit (events.js:326:22)
    at endReadableNT (_stream_readable.js:1241:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  config: {
    url: 'https://my-domain.us.auth0.com/continue?state=hKFo2SBFNDYtVGFjYjE2NzdJMWt2UkRydXlfQzB6OVNrcnlheaFuqHJlZGlyZWN0o3RpZNkgVnpETTNvREJjMk11aDBBX2duZ1NPRENMNzhjR0J0NHSjY2lk2SBDR2ZaNnZHWE5mSGIxMThxcUVmbHdlVUhqMWt6MG9tUQ',
    headers: {
      Accept: 'application/json, text/plain, */*',
      'User-Agent': 'axios/0.21.0'
    },
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    adapter: [Function: httpAdapter],
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    validateStatus: [Function: validateStatus],
    method: 'get',
    data: undefined
  },
 _header: 'GET /continue?state=hKFo2SBFNDYtVGFjYjE2NzdJMWt2UkRydXlfQzB6OVNrcnlheaFuqHJlZGlyZWN0o3RpZNkgVnpETTNvREJjMk11aDBBX2duZ1NPRENMNzhjR0J0NHSjY2lk2SBDR2ZaNnZHWE5mSGIxMThxcUVmbHdlVUhqMWt6MG9tUQ HTTP/1.1\r\n' +
      'Accept: application/json, text/plain, */*\r\n' +
      'User-Agent: axios/0.21.0\r\n' +
      'Host: premera-getvim.us.auth0.com\r\n' +
      'Connection: close\r\n' +
      '\r\n',
_ended: true,
    res: IncomingMessage {
      _readableState: [ReadableState],
      readable: false,
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      socket: [TLSSocket],
      connection: [TLSSocket],
      httpVersionMajor: 1,
      httpVersionMinor: 1,
      httpVersion: '1.1',
      complete: true,
      headers: [Object],
      rawHeaders: [Array],
      trailers: {},
      rawTrailers: [],
      aborted: false,
      upgrade: false,
      url: '',
      method: null,
      statusCode: 401,
      statusMessage: 'Unauthorized',
      client: [TLSSocket],
      _consuming: false,
      _dumped: false,
      req: [Circular],
      responseUrl: 'https://my-domain.us.auth0.com/continue?state=hKFo2SBFNDYtVGFjYjE2NzdJMWt2UkRydXlfQzB6OVNrcnlheaFuqHJlZGlyZWN0o3RpZNkgVnpETTNvREJjMk11aDBBX2duZ1NPRENMNzhjR0J0NHSjY2lk2SBDR2ZaNnZHWE5mSGIxMThxcUVmbHdlVUhqMWt6MG9tUQ',
      redirects: [],
      [Symbol(kCapture)]: false
    },

Are you using a social connection? I found a reference to this error where a user was returning this error as a result of using developer keys for their social connection.

according to docs you should redirect to this URL not send the ajax request.

so for express write something like

	res.redirect(`https://domain.auth0.com/continue?state=${req.query.state}`);
 

Thanks for sharing that solution with others!

1 Like

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