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.
- Host: GitHub
- URL: https://github.com/ghivert/authentication
- Owner: ghivert
- License: mit
- Created: 2020-02-23T18:35:19.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-03T11:25:31.000Z (about 3 years ago)
- Last Synced: 2025-02-15T14:47:58.161Z (about 1 year ago)
- Topics: authentication, french-pastries, microservice
- Language: JavaScript
- Homepage:
- Size: 516 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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[_]|