Skip to content

Commit d1ffec5

Browse files
authored
Merge pull request #81 from ProgrammingBuddies/readme
Readme
2 parents d9faaa0 + 156b10a commit d1ffec5

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

README.md

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22

33
API backend for [Programming Buddies](https://github.com/ProgrammingBuddies/programmingbuddies-ui) (projects management)
44

5+
## API documentation
6+
The documentation is dynamically generated by the server using [Swagger](https://swagger.io) and [Swagger UI](https://swagger.io/tools/swagger-ui/)
7+
- To view the documentation run the server using one of the set up guides below and then head to `/docs` endpoint
8+
- e.g. https://localhost:5001/docs for local development
9+
510
## Set up guide: The simple way
611

712
- Set up your [environment](#environment)
813
- Install [docker-compose](https://docs.docker.com/compose/install/) and do `docker-compose up`
14+
- for information on how to authenticate for the API, see [authentication](#authentication)
915

1016
## Set up guide: The 'bothersome' way
1117

@@ -25,6 +31,7 @@ Requirements:
2531
Run the server:
2632
- `pipenv run python src/runserver.py`
2733
- Run with flag `--reset-db` to drop and recreate all tables on start
34+
- For information on how to authenticate for the API, see [authentication](#authentication)
2835

2936
## Environment
3037

@@ -36,19 +43,37 @@ Run the server:
3643
- Create a new one and set the homepage url to `https://localhost:5001/` and Authorization callback to `https://localhost:5001/login/github/authorized`
3744
- Copy the Client Id and Client Secret from that site and save them in `.env` as `GITHUB_ID` and `GITHUB_SECRET` respectively
3845
4. Furthermore a `JWT_SECRET_KEY` is required for signing the JWT-tokens
46+
- Pick a strong passphrase so that attackers can't brute-force it and sign tokens distinguishing as your server
3947

4048
Your `.env` file should now look something like [example.env](https://github.com/ProgrammingBuddies/programmingbuddies-api/blob/develop/example.env)
4149

42-
### Testing
50+
## Authentication
51+
- To authenticate you have to specify several attributes
52+
- `account` - currently `github` is the only supported value
53+
- `username` - your username of account on specified platform in the previous point
54+
- `redirect` - url where should you be redirected after authenticating with OAuth
55+
- Put it all these together `https://<url:port>/<login-or-register>?account=<account>&username=<username>&redirect=<redirect>`
56+
- e.g.: `https://localhost:5001/<login-or-register>?account=github&username=freddy&redirect=https://localhost:5001` will `login-or-register` using GitHub account with name `freddy` while developing local with the server hosted on `localhost:5001`
57+
- You will be redirected to the specified url and get data with it
58+
- If the request **failed** - when logging in and user was not registered (user not found in the database) or there was any internal error, you will get an error message and code
59+
- If the request **succeeded** - you will get a JWT `token` in the URL, that is what you need to authenticate
60+
- Add to your requests `Authorization` header with a value `Bearer <token>` where you replace `<token>` with your `token` acquired in the step above
61+
#### Login
62+
- `/login` route logs in if the user exists in the database, otherwise returns a error message and code in the URL
63+
- Usage: `https://<url:port>/login?account=<account>&username=<username>&redirect=<redirect>`
64+
- e.g.: `https://localhost:5001/login?account=github&username=freddy&redirect=https://localhost:5001`
65+
66+
#### Register
67+
- `/register` route either logs in if the user exists in the database or registers (creates) a new user, in case of failure returns a error message and code in the URL
68+
- Usage: `https://<url:port>/register?account=<account>&username=<username>&redirect=<redirect>`
69+
- e.g.: `https://localhost:5001/register?account=github&username=freddy&redirect=https://localhost:5001`
70+
71+
## Testing
4372

44-
- to run multiple tests just specify the directory which contains them for example `pipenv run pytest tests/`
45-
- - this will run all the tests in the `tests` directory
46-
- if you want to run test cases only in a particular file, then just give the full file path `pipenv run pytest tests/example.py`
73+
- To run multiple tests just specify the directory which contains them for example `pipenv run pytest tests/`
74+
- This will run all the tests in the `tests` directory
75+
- If you want to run test cases only in a particular file, then just give the full file path `pipenv run pytest tests/example.py`
4776

48-
## Milestones
49-
- [ ] build DB and endpoints with basic CRUD
50-
- [ ] add security for app (ie - bots, and non-human actors/clients)
51-
- [ ] add users and profile stores as well as registration/management API endpoints for users
5277
## Tech stack:
5378

5479
- Python

example.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CONNECT=mysql+mysqlconnector://user:password@localhost:3306/meintest
22
FLASK_ENV=development
3-
APP_SECRET=guest
3+
APP_SECRET=ThisShouldBeSomeSuperHardToGuessPassphrase-ByNotChangingThisDefaultValueYouPutYourServicesIntoRisk
44
GITHUB_ID=c1fed8b3f0e10e0beef
55
GITHUB_SECRET=de79b512d6fbeefa9cdc113beef219ccc7cd98f1
6-
JWT_SECRET_KEY=guest
6+
JWT_SECRET_KEY=ThisTooShouldBeSomeSuperHardToGuessPassphrase-ByNotChangingThisDefaultValueYouPutYourServicesIntoRisk
61.9 KB
Loading

0 commit comments

Comments
 (0)