Help with authentication

Hello guys, I’m having an issue that I can’t figure out how to solve it.
I’m acessing an API through Insomnia, get an auth token and I’m able to use it on another endpoints, bu can’t make it work within n8n using header or basic auth.

image

This POST request returns me the following JSON:
{
“auth”: {
“auth_token”: “aDiewj2wmqfIxdkIb1d5dle4yjGzuRy0UoaydMQa”,
}
}

So I use it to make the subsequent requests, like this one:

There is no Body or Headers and it returns the logs
image

On n8n i used an HTTP Node with Basic Auth:


Tried also using Header Auth

But no success and aways getting the error below.

ERROR: Authorization failed - please check your credentials
401 - “{"error":"Unauthorized","message":"Invalid authorization"}\n”

  • n8n version: 1.11.1
  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud

Expressions in credentials are a bit more sensible, you have to use the node name to get the correct data, so in your last screenshot, you need to use {{ "Basic: " + ${'NodeName').auth.encodedAuth }} and even then it might not work.

The safest route is not use any credentials, just set a custom header as part of the Http Request node, as can be seen in the workflow below:

Please note the .hash('base64') as this is necessary for auth basic.

1 Like

Sadly it didn’t work.

I have even copied the token from insomnia and set a fixed value on Basic Auth and didn’t work.
Tried the other option on header too, with fixed token also.

Insomnia with Headers (Working)

n8n with same Header (Not Working)

Hi @felfreitas88

There’s something strange, I just tried using https://httpbin.org/basic-auth/foo/bar to test the authentication. This is a public service to try authentication. The URL segments foo and bar are the username and password respectively. If you try opening this in your browser, you should be prompted for the credentials.

Using the workflow below, it all works:

I hope this helps you identify what might be happening.

Hello, guys, I can’t by any reason make this to work, I found the logs on Insomnia and I realized that are some redirects. Can you help me again to check if this can give any direction to solve this issue?

This is the API docs:
Mailcheap API Docs

This printscreen shows all that is included on the request.

This is the logs on the request I made to the endpoint that gives me a 200 response.

* Preparing request to https://mail.express.dev.br/api/v1/server/logs/postfix
* Current time is 2023-10-29T14:16:26.852Z
* Enable automatic URL encoding
* Using default HTTP version
* Enable timeout of 30000ms
* Enable SSL validation
* Found bundle for host mail.express.dev.br: 0x1e5b8b3af40 [can multiplex]
* Re-using existing connection! (#0) with host mail.express.dev.br
* Connected to mail.express.dev.br (51.83.104.208) port 443 (#0)
* Using Stream ID: 9 (easy handle 0x1e5bca86e10)
* TLSv1.2 (OUT), TLS header, Supplemental data (23):

> GET /api/v1/server/logs/postfix HTTP/2
> Host: mail.express.dev.br
> user-agent: insomnia/2023.5.8
> authorization: Basic YWRtaW46MGd5ZWdTS0NTb2Y3S0tBMFRhRmRETVVqTWh4RVBnd2FlR2xjbVBhcw==
> accept: */*

* TLSv1.2 (IN), TLS header, Supplemental data (23):

< HTTP/2 308 
< server: nginx/1.18.0
< date: Sun, 29 Oct 2023 14:16:17 GMT
< content-type: text/html; charset=utf-8
< content-length: 314
< location: http://mail.express.dev.br/api/v1/server/logs/postfix/
< access-control-allow-origin: *
< access-control-allow-headers: Content-Type, Authorization
< access-control-allow-methods: GET, OPTIONS, HEAD, POST, PUT, PATCH, DELETE


* Ignoring the response-body
* Received 314 B chunk
* Connection #0 to host mail.express.dev.br left intact
* Issue another request to this URL: 'http://mail.express.dev.br/api/v1/server/logs/postfix/'
*   Trying 51.83.104.208:80...
* Connected to mail.express.dev.br (51.83.104.208) port 80 (#1)

> GET /api/v1/server/logs/postfix/ HTTP/1.1
> Host: mail.express.dev.br
> User-Agent: insomnia/2023.5.8
> authorization: Basic YWRtaW46MGd5ZWdTS0NTb2Y3S0tBMFRhRmRETVVqTWh4RVBnd2FlR2xjbVBhcw==
> Accept: */*

* Mark bundle as not supporting multiuse

< HTTP/1.1 301 Moved Permanently
< Server: nginx/1.18.0
< Date: Sun, 29 Oct 2023 14:16:18 GMT
< Content-Type: text/html
< Content-Length: 169
< Connection: keep-alive
< Location: https://mail.express.dev.br/api/v1/server/logs/postfix/


* Ignoring the response-body
* Received 169 B chunk
* Connection #1 to host mail.express.dev.br left intact
* Issue another request to this URL: 'https://mail.express.dev.br/api/v1/server/logs/postfix/'
* Found bundle for host mail.express.dev.br: 0x1e5b8b3af40 [can multiplex]
* Re-using existing connection! (#0) with host mail.express.dev.br
* Connected to mail.express.dev.br (51.83.104.208) port 443 (#0)
* Using Stream ID: b (easy handle 0x1e5bca86e10)
* TLSv1.2 (OUT), TLS header, Supplemental data (23):

> GET /api/v1/server/logs/postfix/ HTTP/2
> Host: mail.express.dev.br
> user-agent: insomnia/2023.5.8
> authorization: Basic YWRtaW46MGd5ZWdTS0NTb2Y3S0tBMFRhRmRETVVqTWh4RVBnd2FlR2xjbVBhcw==
> accept: */*

* TLSv1.2 (IN), TLS header, Supplemental data (23):

< HTTP/2 200 
< server: nginx/1.18.0
< date: Sun, 29 Oct 2023 14:16:18 GMT
< content-type: text/html; charset=utf-8
< content-length: 861020
< vary: Accept-Encoding
< access-control-allow-origin: *
< access-control-allow-headers: Content-Type, Authorization
< access-control-allow-methods: GET, OPTIONS, HEAD, POST, PUT, PATCH, DELETE


* Received 7.8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 4 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 4 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 4 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 4 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 4 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 4 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 4 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 4 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 4 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 4 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 4 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 4 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 8 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 16 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 16 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 16 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 16 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 90 B chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 16 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 16 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 16 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 16 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 72 B chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 16 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 16 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 16 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 16 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 72 B chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 16 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 16 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 16 KB chunk
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Received 9 KB chunk
* Connection #0 to host mail.express.dev.br left intact

I found the solution!

This post Output all redirect headers and their status codes - Questions - n8n took me to this site Deref to check the redirects and found this result:

image

So I added the slash to the end of the URL and my request worked!