2021-10-17 18:26:00 +02:00
|
|
|
---
|
|
|
|
title: Oauth
|
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
## Oauth initialisation
|
2021-10-17 18:26:00 +02:00
|
|
|
```
|
|
|
|
POST /oauth/init
|
|
|
|
{
|
|
|
|
'provider': 'github',
|
|
|
|
'language': 'fr'
|
|
|
|
}
|
|
|
|
```
|
2021-08-25 16:09:31 +02:00
|
|
|
On success:
|
2021-10-17 18:26:00 +02:00
|
|
|
```
|
|
|
|
200
|
|
|
|
{
|
|
|
|
'state': '5d5132041ad3f369443f1d7b'
|
|
|
|
}
|
|
|
|
```
|
2021-08-25 16:09:31 +02:00
|
|
|
On failure:
|
2021-10-17 18:26:00 +02:00
|
|
|
```
|
|
|
|
400
|
|
|
|
```
|
|
|
|
- This triggers an Oauth flow
|
|
|
|
- `provider` should be one of `google` or `github`
|
|
|
|
- `language` should be one of the [configured language codes](https://github.com/freesewing/backend/blob/develop/src/config/index.js#L32)
|
|
|
|
- The frontend will use the state value to initialize an Oauth session. We'll check the state value when we receive the Oauth callback at the backend
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
## Oauth callback
|
2021-10-17 18:26:00 +02:00
|
|
|
```
|
|
|
|
GET /oauth/callback/from/:provider
|
|
|
|
```
|
2021-08-25 16:09:31 +02:00
|
|
|
On success: Redirects to the frontend
|
|
|
|
|
2021-10-17 18:26:00 +02:00
|
|
|
This is part of the Oauth flow. It fetches the user info from the Oauth provider. If it can't match it with a user, it will create a user account.
|
2021-08-25 16:09:31 +02:00
|
|
|
In other words, this will handle both log in and sign up.
|
|
|
|
|
|
|
|
The frontend redirect will contain a confirmation ID in the URL that we'll `POST` back in the next Oauth flow step.
|
|
|
|
|
|
|
|
## Oauth login
|
2021-10-17 18:26:00 +02:00
|
|
|
```
|
|
|
|
POST /oauth/login
|
|
|
|
{
|
|
|
|
'confirmation': '98e132041ad3f369443f1d3d'
|
|
|
|
}
|
|
|
|
```
|
2021-08-25 16:09:31 +02:00
|
|
|
On success: The account data
|
|
|
|
On failure:
|
2021-10-17 18:26:00 +02:00
|
|
|
```
|
|
|
|
400
|
|
|
|
```
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2021-10-17 17:34:55 +02:00
|
|
|
This is the last step of the Oauth process. It logs a user in.
|
2021-10-17 18:26:00 +02:00
|
|
|
|