npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@zeytech/cognito-adonisjs

v2.0.4

Published

Zeytech AdonisJS plugin to help integrate Cognito for authentication

Downloads

43

Readme

Table of contents

cognito-adonisjs

npm-image license-image typescript-image

cognito-adonisjs is a plugin created to make server setup of Cognito authorization quick and easy when using Adonis on your backend.

Local Development Testing

npm run publish:local

Then, in your consuming app:

  • npm uninstall @zeytech/cognito-adonisjs
  • npm i --save-peer ../path/to/cognito-adonisjs/pkg-local/zeytech-cognito-adonisjs-*.tgz

Example NPM script used in demo api (scripts block of package.json):

"update:plugin:cognito": "npm uninstall @zeytech/cognito-adonisjs && npm i --save-peer ../cognito-adonisjs/pkg-local/`ls ../cognito-adonisjs/pkg-local/*.tgz | xargs -n 1 basename`"

When testing, use the following process:

  • In this repository/project: npm run publish:local
  • Stop dev server (if not already stopped)
  • Restart dev server (npm run dev:plugin)

Installation

npm i @zeytech/cognito-adonisjs

Configuration

node ace configure @zeytech/cognito-adonisjs

  • Question - Do you want me to generate a controller for Cognito service calls?

If yes, this will create a CognitoController.ts file in the app/Controller/Http folder with already created functions to access basic Cognito API calls.

  • Automatic Action - Config file creation

A zeytech-cognito.ts file will be created in the config folder that contains config information for the plugin; do not edit this file.

  • Question - Where would you like to show environment information?

In The Browser will show the information in your default browser and In Terminal will show the information in the terminal where you ran the node ace configure command. Take the information shown and copy and paste it in the env.ts file.

Install Dependencies

  • Redis

npm i redis

Add the following to the .env file (if not already there upon install):

REDIS_CONNECTION=local REDIS_HOST=127.0.0.1 REDIS_PORT=6379 REDIS_PASSWORD=

Ensure the following is added to the env.ts file (if not already there upon install):

REDIS_CONNECTION: Env.schema.enum(['local'] as const),
REDIS_HOST: Env.schema.string({ format: 'host' }),
REDIS_PORT: Env.schema.number(),
REDIS_PASSWORD: Env.schema.string.optional(),

env Variables

Add the following Cognito variables to the .env file:

COGNITO_CLIENT_ID=<client_id_from_AWS_Cognito_account> COGNITO_USER_POOL_ID=<User_pool_ID_from_user_pool_that_was_created_in_AWS_Cognito_account> COGNITO_DOMAIN=<Cognito_domain_found_in_AWS_Cognito_account_under_user_pool_App_Integration_tab> COGNITO_REGION=<region_part_of_COGNITO_DOMAIN> Ex: us-east-1

Usage

  • In the start/kernel.ts file, add the following code under the Named Middleware section. If a Server.middleware.registerNamed block already exists, only add the 'cognitoAuth' line inside.
Server.middleware.registerNamed({
  'cognitoAuth': () => import('@ioc:Adonis/Addons/Zeytech/AuthenticateMiddleware')
})
  • In the start/routes.ts file, add .middleware('cognitoAuth') to any routes you would like to protect with Cognito authentication.

Ex:

Route.group(() => {
  Route.group(() => {
    Route.group(() => {
      Route.get('/:id?', 'UserController.index')
      Route.post('/', 'UserController.create')
    }).prefix('/users')
  }).middleware('cognitoAuth') <-- Added to Route group
}).prefix('/api')
Route.group(() => {
  Route.group(() => {
    Route.get('/:id?', 'UserController.index')
    Route.post('/', 'UserController.create').middleware('cognitoAuth') <-- Added to individual route
  }).prefix('/users')
}).prefix('/api')