Microgateway : Apikey and OAuth access token generation not working

Not applicable

Hi Team,

I am trying to secure microgateway proxies with OAuth / APIkey and it does not seem to work for me.

1. With APIKey :

Getting invalid_token error. The Products are properly configured with edgemicro_* & edgemicro_auth proxies and / & /** in Resource path. Curl command and error logs below.

curl -X GET \ http://localhost:8000/edgemicro_fin_test \ -H 'cache-control: no-cache' \ -H 'postman-token: 43463ed0-a155-c16b-2c1e-fe050830fb11' \ -H 'x-api-key: MY_DEVELOPER_APP_KEY'

Debug enabled error trace:

plugin:oauth invalid token +6m plugin:oauth auth failure 401 invalid_token { host: 'localhost:8000', connection: 'keep-alive', 'cache-control': 'no-cache', 'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KH ML, like Gecko) Chrome/61.0.3163.100 Safari/537.36', 'x-api-key': 'ohyA2e7K9d5hDHYsOP1dNP4i8ozK5S27', 'postman-token': '0e9f623d-d1d5-f82c-5183-20ce5fe3a3a8', accept: '*/*', 'accept-encoding': 'gzip, deflate, br', 'accept-language': 'en-US,en;q=0.8' } GET /edgemicro_fin_test +1ms gateway:errors invalid_token +1s analytics flushing 1 records. 0 records remaining. +73ms

2. With OAuth :

Could not generate access token using Consumer key and secret, see error below.

C:\Users\admin>edgemicro token get -o myorg -e dev -i DEV_APP_KEY -s DEV_APP_SECRET

current nodejs version is v6.10.1 current edgemicro version is 2.5.4 <!DOCTYPE html> <html> <head> <title>Error</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>An error occurred.</h1> <p>Sorry, the page you are looking for is currently unavailable.<br/> Please try again later.</p> </body> </html>

Configuration in myorg-dev-config.yaml is as below

plugins:

dir: ../plugins

sequence:

- oauth

The proxy works fine without authorization if the oauth sequence is removed. However, gives above mentioned error when oauth sequence is added though the product,consumer key and secret are correct.

Can someone help with this?

0 4 851
4 REPLIES 4

Former Community Member
Not applicable

It looks like the https://{org}-{test}.apigee.net/edgemicro-auth endpoint is unavailable or not reachable (based on the second error).

Thanks for the reply. The https://.../edgemicro-auth endpoint is reachable. I am able to get the token using CURL command.

curl -i -X POST "http://myorg-test.apigee.net/edgemicro-auth/token" -d '{ "client_id": "CLIENT_ID", "client_secret": "SECRET", "grant_type": "client_credentials" }' -H "Content-Type: application/json"

HTTP/1.1 200 OK

Date: Mon, 09 Oct 2017 07:26:06 GMT

Content-Type: application/json

Content-Length: 911

Connection: keep-alive

Server: Apigee Router

{"token":"tokenstring"}

But, generating token using edgemicro token get command is not working, does it need any changes in the config.yaml file? Auth uri in the yaml file is "authUri: 'https://%s-%s.apigee.net/edgemicro-auth' ". Tried changing this endpoint to https://myorg-test-apigeenet/edgemicro-auth which throws nodeapp error.

Also, did some debugging on the apikey and oauth issue and the findings are

1. Verifyapikey api from Apigee Edge is called and its successful 200.

2. VerifyApikey returns JWT token to Microgateway.

3. The JWT token validation fails in Microgateway in oauth plugin.

Same issue is happening in edgemicro 2.5.4 and 2.4.6 version.

Any help is appreciated.

Former Community Member
Not applicable

Ok, so now you can get a token. Then I suspect the same issue as here: https://community.apigee.com/questions/47846/microgateway-not-working-with-oauth.html

Thanks @Srinandan Sridhar, Did bit of debugging and the issue turns out to be time sync between Edge and MGW. System time of Microgateway was ahead of Edge and the token was already expired throwing 401 error.