1.67.0 • Published 3 years ago

padlocks v1.67.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Disclaimer

This library is a work in progress! I built and tested Padlocks solely for applications that I am currently developing. Accordingly, the API may change at any time, bugs may exist, and you may not agree with all the security decisions I have made. Don’t say didn’t warn you!

Overview

Padlocks is an authentication library, built using Express.js, TypeORM, and PostgresSQL that is designed to work with Hasura.

Essentially, it exposes one function, createAuthServer, that creates an Express.js app. On that Express.js app, in turn, are routes, under the /auth url, that enable a user to:

  • Login with Facebook or Google.

    • If the Facebook or Google ID of the user does not exist in the local database, a user profile will be created in the local database, and then in Hasura.
    • Any social login will culminate in an access token (JWT) and refresh token (opaque string) being sent to the client.
  • Refresh that access token using the refresh token.

  • Delete a user profile in the local database, then delete that profile in Hasura

To see what routes are exposed by this application, see the code here

Requirements

  • You must have a Hasura account. Within that account, your “User” object should be called profiles and it should have, at minimum, two fields. An id field, which is the primary key and an auto-generated uuid, and the auth_id field, mapped to authId, which is a unique, non-nullable text field.

The auth_id is the foreign key that will:

  • Exist on all other Hasura objects
  • Be present on the access token (JWT) sent to Hasura
  • Will look something like google-oauth2|1322323728328.

Instructions

  1. Install the package by running yarn install padlocks.

  2. Run yarn padlocks configure. Then, fill in the generated .env file. Without this step, the social login and the connection to Hasura will not work.

  3. Create an index.js or index.ts file, using this one as a template. Read the comments in the file carefully!

  4. Create an ormconfig.js file, using this one as a template. Read the comments in the file carefully!

  5. If you want to test it locally, generate SSL certificates in the root of your server. I recommend installing the mkcert library and then running mkcert localhost.

  6. Add these scripts to your package.json. You will need them to migrate and revert your database, as well as to push the application to production, and then run it. Read the TypeORM documentation for more details.

{ 
  "scripts": {
    "deploy": "yarn install && yarn build && yarn migrate",
    "makemigrations": "ts-node ./node_modules/typeorm/cli.js migration:generate --name",
    "migrate": "ts-node ./node_modules/typeorm/cli.js migration:run",
    "revert": "ts-node ./node_modules/typeorm/cli.js migration:revert",
    "start-production": "node build/index.js",
  }
}
  1. Run the commands yarn makemigrations "CreateProfile" and then yarn migrate to configure the database.

  2. At this point, it should work like a normal Express.js app. Use yarn start to run the application locally and yarn build to create the production build.

1.67.0

3 years ago

1.66.0

3 years ago

1.65.0

3 years ago

1.64.0

3 years ago

1.63.0

3 years ago

1.61.0

3 years ago

1.62.0

3 years ago

1.59.0

3 years ago

1.60.0

3 years ago

1.58.0

3 years ago

1.57.0

3 years ago

1.56.0

3 years ago

1.53.0

3 years ago

1.54.0

3 years ago

1.52.0

3 years ago

1.49.0

3 years ago

1.51.0

3 years ago

1.50.0

3 years ago

1.48.0

3 years ago

1.47.0

3 years ago

1.46.0

3 years ago

1.44.0

3 years ago

1.45.0

3 years ago

1.39.0

3 years ago

1.40.0

3 years ago

1.42.0

3 years ago

1.41.0

3 years ago

1.43.0

3 years ago

1.37.0

3 years ago

1.38.0

3 years ago

1.36.0

3 years ago

1.35.0

3 years ago

1.34.0

3 years ago

1.25.0

3 years ago

1.26.0

3 years ago

1.23.0

3 years ago

1.29.0

3 years ago

1.27.0

3 years ago

1.28.0

3 years ago

1.30.0

3 years ago

1.31.0

3 years ago

1.22.0

4 years ago

1.14.0

4 years ago

1.13.0

4 years ago

1.12.0

4 years ago

1.19.0

4 years ago

1.18.0

4 years ago

1.17.0

4 years ago

1.16.0

4 years ago

1.21.0

4 years ago

1.20.0

4 years ago

1.11.0

4 years ago

1.0.0

4 years ago