cognito-express | Authenticates API requests on a Node application | AWS library
kandi X-RAY | cognito-express Summary
kandi X-RAY | cognito-express Summary
Authenticates API requests on a Node application by verifying the JWT signature of AccessToken or IDToken generated by Amazon Cognito.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of cognito-express
cognito-express Key Features
cognito-express Examples and Code Snippets
Community Discussions
Trending Discussions on cognito-express
QUESTION
I'm having trouble to understand why using a callback, which always returns an empty object. And pass the param to this callback.
https://github.com/ghdna/cognito-express/blob/master/lib/strategy.js#L20
I'm assuming this guarantee the Promise is either resolved or rejected.
...ANSWER
Answered 2019-Jul-10 at 07:31In your own code you would never do that: once you use promises, there is no gain in using the old-style callback system.
Apparently the author of this API wanted to offer both callback-based and promise-based support via the init
method, so that the client of that API could still choose, or maintain compatibility with a previous version of this API which might have only supported the callback-style.
Now the init
method takes a required callback argument: if it would not be passed, there would be an exception when callback()
is executed. This is a weak spot in the API, because now the constructor code (which belongs to the API itself) needs to pass a callback argument to its own call of init
. Although that constructor does not need to be "called back", it must provide a valid callback, and so it passes a dummy one:
QUESTION
This is my Library function file named verifyToken.js
...ANSWER
Answered 2018-Jun-22 at 08:13It is becuase cognitoExpress.validate
is an async
operation. it will run and the callback of this function will run. But by the time this all happens. Your following line
console.log(auth);
gets hit already and you see undefined becuase you are actually not returning anything from verifyToken
method at that time.
This how javascript and async operations work.
You can either use the callback approach but that's not what I would recommend. So I'm modifying your code with promises
and see if it works for you.
Your verifyToken.js should look as follow:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install cognito-express
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page