https://github.com/fanqingsong/fastapi-react-postgres-keycloak-sso
https://github.com/fanqingsong/fastapi-react-postgres-keycloak-sso
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/fanqingsong/fastapi-react-postgres-keycloak-sso
- Owner: fanqingsong
- Created: 2023-05-12T14:30:27.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-05-17T15:50:31.000Z (about 2 years ago)
- Last Synced: 2025-01-14T13:53:50.648Z (5 months ago)
- Language: Python
- Size: 835 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# fastapi-react-postgres-keycloak
To launch all the services just execute:
```bash
docker-compose up -dor
docker-compose down && docker-compose build && docker-compose up
```## Keycloak installation
Create a `.env` file based on the `.env.example` file.
> :warning: Don't forget to put values for the password fields
Next step is to launch keycloak:
```bash
docker-compose up -d keycloak
```To initialize Keycloak with a client and a user, you can use the script in the keycloak folder. Find out more about the API calls made in the [Keycloak doc](https://www.keycloak.org/docs-api/5.0/rest-api/index.html).
> You can change the script to have different values for the client name, username, password...
```bash
bash keycloak/init.sh
```In the output of the script you will find the client secret. Copy it and put it the `.env`.
You can then access the keycloak console and login with the admin credentials: http://localhost:8080
## Running database migrations using [Alembic](https://alembic.sqlalchemy.org).
First, modify your models in the file `database/models.py`.
Then run the following command to generate the migration:```bash
docker-compose exec backend alembic revision --autogenerate -m ""
```> :warning: Check this [page](https://alembic.sqlalchemy.org/en/latest/autogenerate.html#what-does-autogenerate-detect-and-what-does-it-not-detect) to see what alembic detects for the Autogenerate
Check the migration file in the `alembic/versions` folder. If you are happy with it, you can run the migration:
```bash
docker-compose exec backend alembic upgrade head
```Your database is now up to date !
## Generate fake data
To facilitate development, you can generate some fake data by running the following command:
```bash
docker-compose exec backend python fake_data.py
```## Create frontend app
In frontend folder, run:
```bash
npx create-react-app app --template typescript --use-npm
```