Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jill64/cognito-serverless
🔑 AWS Cognito Hosted UI OAuth on Serverless
https://github.com/jill64/cognito-serverless
aws cognito hosted-ui serverless
Last synced: 2 months ago
JSON representation
🔑 AWS Cognito Hosted UI OAuth on Serverless
- Host: GitHub
- URL: https://github.com/jill64/cognito-serverless
- Owner: jill64
- License: mit
- Created: 2024-02-19T09:57:04.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-10-29T17:14:16.000Z (3 months ago)
- Last Synced: 2024-10-29T18:40:28.713Z (3 months ago)
- Topics: aws, cognito, hosted-ui, serverless
- Language: TypeScript
- Homepage: https://npmjs.com/package/cognito-serverless
- Size: 534 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cognito-serverless
🔑 AWS Cognito Hosted UI OAuth on Serverless
## Installation
```sh
npm i cognito-serverless
```## Usage
Add code in your middleware or route to authenticate user.
```js
import { Auth } from 'cognito-server'const cognito = new Auth(
{
COGNITO_DOMAIN: 'auth.example.com',
COGNITO_CLIENT_ID: 'client-id',
COGNITO_CLIENT_SECRET: 'client-secret',
// State is a random string to prevent CSRF attacks (optional)
COGNITO_STATE: 'random-string'
},
/*
* The scopes of the access request.
* @optional
* @default ['openid', 'profile', 'email']
*/
scopes: ['openid', 'profile', 'email']/*
* After successful authentication, the user will be redirected to this URL.
* @optional
* @default url.origin
*/
redirect_uri: 'https://example.com/callback'
)/* UserInfo | URL */
const result = await cognito.auth({
url: new URL('https://example.com'),
cookies: {
get: (key) => {
/** get cookie */
}
set: (key, value, options) => {
/** set cookie */
}
},
// Override class config (optional)
redirect_uri: 'https://example.com/callback'
})if (typeof result === 'string') {
/* Please redirect to `result` (Cognito Hosted UI) */
}else {
/* User is authenticated */
}```
## License
[MIT](LICENSE)