https://github.com/dkatz23238/basic-auth-tutorial
Basic introduction to implementing access tokens with python and mysql
https://github.com/dkatz23238/basic-auth-tutorial
Last synced: 3 months ago
JSON representation
Basic introduction to implementing access tokens with python and mysql
- Host: GitHub
- URL: https://github.com/dkatz23238/basic-auth-tutorial
- Owner: dkatz23238
- Created: 2022-03-25T22:55:41.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-03-25T22:55:51.000Z (about 3 years ago)
- Last Synced: 2025-01-19T08:28:20.914Z (4 months ago)
- Language: Python
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Introduction to Auth
This projects is set to work with python `3.8`.# Run Db and create tables
```
./run_db.sh
sleep 25
cat tables.sql | mysql --user=root --host=127.0.01 --port=3306 -proot;
```# Run Web Server
```
python -m pip install -r requirements.txt
uvicorn app:app
```*Authentication* -> Who are you?
*Authorization* -> What are you allowed to do?### Create Key Pair for Signing
[Create](https://gist.github.com/rxm/6d5b51c5b947144e9e1ea6fcb8abb9ec) a private key first with openssl, then create a public key from that private key, make sure the keys are in `pem` format and that they are called `jwt-key` and `jwt-key.pub`.### Signup
```sh
curl -H "Content-Type: application/json" -d '{"username":"david","password":"crossentropy"}' localhost:8000/signup | jq
```### Authenticate
```sh
TKN=$(curl -H "Content-Type: application/json" -d '{"username":"david","password":"crossentropy"}' localhost:8000/authenticate | jq -r ".access_token")
echo $TKN
```### Get Users
```sh
curl -H "Authorization: Bearer $TKN" localhost:8000/user | jq;
```### Get Protected
```sh
curl -H "Authorization: Bearer $TKN" localhost:8000/protected | jq;
```