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

@gimme-my-money/authentication

v0.1.2

Published

Authentication provides an easy to install, easy to use authentication micro-service. While still being in development, it allows to sign up, sign in, and log in and out user right now. Of course more features are planned and on the roadmap.

Downloads

2

Readme

Authentication

Authentication provides an easy to install, easy to use authentication micro-service. While still being in development, it allows to sign up, sign in, and log in and out user right now. Of course more features are planned and on the roadmap.

This project is born on an idea and major participations of arthurescriou. This project would not live without him. Take a look at what he’s doing. I mainly mirrored his code.

Roadmap

  • [x] Reset Password
  • [ ] Delete user account
  • [ ] OAuth2
  • [ ] Back Office built-in

How it works?

It automatically connects to your Bakery in order to provide its service and communicate with the outside world.

Getting Started

yarn add @gimme-my-money/authentication

To get it running, you need some parameters in your environment. You can use a .env at your root launch, the Authentication will automatically read it.

In the environment you need many variables.

  • RSA_PRIVATE_KEY An RSA private key.
  • RSA_PUBLIC_KEY The corresponding RSA public key.
  • PORT The port on which the server is running.
  • HOSTNAME The hostname on which the Authentication is running.
  • REGISTRY_HOST The host on which the Bakery is running.
  • REGISTRY_PORT The port on which the Bakery is running.
  • DATABASE_URL The PostgreSQL database URI.
  • ORIGIN The address from where you’re communicating.
  • AES_KEY The AES key for crypting.
  • AES_IV The AES param.
  • SENDGRID_API_KEY Your sendgrid API key.

Then you can install the Authentication:

yarn add @frenchpastries/authentication

And start it right away!

const Authentication = require('@frenchpastries/authentication')

Authentication.start()

To call it from your application:

Sign In

const mySignInHandler = request => {
  const { username, password } = request.body
  const response = await request.services.authentication
    .signIn()
    .post({
      body: JSON.stringify({
        username,
        password,
      })
    })
  const token = await response.text()
  // Here is the resulting token.
}

Sign Up

const mySignUpHandler = request => {
  const { username, password } = request.body
  const response = await request.services.authentication
    .signUp()
    .post({
      body: JSON.stringify({
        username,
        password,
      })
    })
  const token = await response.text()
  // Here is the resulting token.
}

Check token

const myCheckTokenHandler = request => {
  const { token } = request.headers.Authorize
  const response = await request.services.authentication
    .checkToken()
    .post({ body: JSON.stringify({ token }) })
  const userId = await response.text()
  // Here is the resulting user UUID.
}

Delete session

const mySignOutHandler = request => {
  const { token } = request.headers.Authorize
  const response = await request.services.authentication
    .signOut()
    .delete({ body: JSON.stringify({ token }) })
  const ok = await response.text()
  // assert(ok === 'OK')
}

Reset password link

const myResetPasswordHandler = ({ body }) => {
  const response = await request.services.authentication
    .sendMailReset()
    .post({ body })
  const ok = await response.text()
  // assert(ok === 'OK')
}

Change password

const myChangePasswordHandler = ({ body }) => {
  const response = await request.services.authentication
    .resetPassword()
    .post({ body })
  const ok = await response.text()
  // assert(ok === 'OK')
}

Full API

The API is RESTful. All requests should contain a JSON body.

User creation.

Creates a user and a session. Returns the JWT of the session.

POST /sign-up

{
  "username": "[email protected]",
  "password": "73|2|2Ys[_]|<S!"
}
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

Creates a user and a session. Returns the JWT of the session.

Authentication.

Creates a session for a registered user. Returns the JWT of the session.

POST /sign-in

{
  "username": "[email protected]",
  "password": "73|2|2Ys[_]|<S!"
}
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

Token checking

Check if a session is still active and if the token is valid. Returns user UUID if everything is correct.

POST /check-token

{ "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" }
c751dcf0-4efe-43e9-99c4-acdb8b995d04

Log out

Set the session as invalid. Returns OK.

DELETE /sign-out

{ "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" }
OK

Reset password link

Send an email for reseting password. Returns OK.

POST /reset-password

{ "username": "[email protected]" }
OK

Change password

Reset the password. Returns OK.

POST /reset-password

{ "password": "New-password", "resetId": "XXXXXXXXXXXXXX" }
OK