1

I'm getting an Error 404 when trying to set my authorization key (key-auth) in the request header. I'm sure that there isn't any problem with my key because if I don't set it a Forbidden status will return.

before setting any credentials:

$ curl http://localhost:8080/ip

will return:

{
  "origin": "5.116.28.133"
}

after creating a key-auth credential:

$ curl -H "Authorization: apiKey ${keyId}:${keySecret}" http://localhost:8080/ip

will return:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /ip</pre>
</body>
</html>

and it's my gateway config:

http:
  port: 8080
admin:
  port: 9876
  hostname: localhost
apiEndpoints:
  api:
    host: localhost
    paths: '/ip'
serviceEndpoints:
  httpbin:
    url: 'https://httpbin.org'
policies:
  - basic-auth
  - cors
  - expression
  - key-auth
  - log
  - oauth2
  - proxy
  - rate-limit
pipelines:
  - name: default
    apiEndpoints:
      - api
    policies:
    - key-auth:
      - proxy:
          - action:
              serviceEndpoint: httpbin 
              changeOrigin: true

Does anyone know why this issue happens?

find more information about express-gateway from http://www.express-gateway.io/

Ronan Quillevere
  • 3,699
  • 1
  • 29
  • 44
Aref
  • 93
  • 3
  • 13
  • where are you handling the headers in node, there might be some bug there ? Or flow is not reaching there ? – Amit Yadav Aug 06 '17 at 16:54
  • @Aky_0788 I don't handle anything. it's all handled in http://express-gateway.io if you see their sample they set credentials any use authorization key in header without any problem. – Aref Aug 07 '17 at 04:48

2 Answers2

3

it should be key-auth the problem is with indentation

- key-auth:
       - proxy:

it must be on one level

basically this is an array:

policies: [{
    'key-auth':null
    },{
    proxy:{ ... }   
}]

this will fix the issue.

Serhii Kuts
  • 429
  • 2
  • 9
  • Same issue here, uncommenting line from getting started demo will not provide correct indentation! Sneaky gotcha. Good catch Sergey Kuts – Merrick Oct 13 '17 at 18:31
0

Try removing the hyphen from key-auth under policies: in your config file - this worked for me. It should just be keyauth.

substrate9
  • 24
  • 2
  • [Currently] removing hyphen from key-auth will cause a configuration error. Perhaps this was a silent error in the past, breaking the auth & permitting requests? – Merrick Oct 13 '17 at 18:56