passport-oauth2
passport-oauth2 copied to clipboard
Internal OAuth2 service
When developing, I have an internal OAuth2 service; however, this lib assumes the public (redirectable) OIDC/OAuth2 tokenURL URI is resolvable when fetching resolving the access token from the authorization code.
It should be possible to specify different public/internal HTTP endpoints.
You can specify any URL you want using options.authorizationURL and options.tokenURL. Is that not sufficient?
I tried doing that, which leads to other internal errors without all details, and I don't know how to get at the actual error contents, so I can't debug it 😞🐼. The status code is 500... Perhaps it's a DNS resolution error server-side that is causing it. I've cloned the repo and am introducing logging throughout to see what the actual error is.
You should be able to put log statements here: https://github.com/jaredhanson/passport-oauth2/blob/master/lib/strategy.js#L402
to get at the original error. That should help identify and DNS or other related issues. Please post here any details you find.
It was initially a DNS issue resolving to 127.0.0.1 and then when changing the token uri, I get this:
getOAuthAccessToken callback err= { statusCode: 502,
data:
'{"error":"error","error_description":"The error is unrecognizable.","status_code":500, "error_debug":"can not serve request over insecure http","request_id":""}\n' }
_createOAuthError message= Failed to obtain access token err= { statusCode: 502,
data:
'{"error":"error","error_description":"The error is unrecognizable.","status_code":500, "error_debug":"can not serve request over insecure http","request_id":""}\n' }
GET /accounts/oauth2/c/site 500 148 30.014ms b8090a5f8ec8b415d76c3412b216752a -
TokenError: The error is unrecognizable.
at OAuth2Strategy.parseErrorResponse (/app/dist/lib/passport-oauth2/strategy.js:241:16)
at OAuth2Strategy._createOAuthError (/app/dist/lib/passport-oauth2/strategy.js:277:22)
at /app/dist/lib/passport-oauth2/strategy.js:94:44
at /app/node_modules/oauth/lib/oauth2.js:191:18
at passBackControl (/app/node_modules/oauth/lib/oauth2.js:132:9)
at IncomingMessage.<anonymous> (/app/node_modules/oauth/lib/oauth2.js:157:7)
at IncomingMessage.emit (events.js:198:15)
at endReadableNT (_stream_readable.js:1139:12)
at processTicksAndRejections (internal/process/task_queues.js:81:17)
Which logs TokenError: The error is unrecognizable. with the error logging code present in this library.
The solution in this case is to fake HTTPS between k8s pods: { 'X-Forwarded-Proto': 'https' } needs to be added as headers... Now if I can find the fetch statement?
https://github.com/jaredhanson/passport-oauth2/pull/93/files#diff-04c6e90faac2675aa89e2176d2eec7d8R105 would have helped to debug this