An open API service indexing awesome lists of open source software.

https://github.com/ghivert/authentication

Authentication service for your micro-service architecture.
https://github.com/ghivert/authentication

authentication french-pastries microservice

Last synced: 12 months ago
JSON representation

Authentication service for your micro-service architecture.

Awesome Lists containing this project

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](https://github.com/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](https://github.com/FrenchPastries/Bakery) in order to provide its service and communicate with the outside world.

## Getting Started

```bash
yarn add @ghivert/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:

```bash
yarn add @frenchpastries/authentication
```

And start it right away!

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

Authentication.start()
```

To call it from your application:

### Sign In

```javascript
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

```javascript
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

```javascript
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

```javascript
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

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

### Change password

```javascript
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`

```json
{
"username": "rick.sanchez@miniverse.com",
"password": "73|2|2Ys[_]|