pslockout/authserver/README.md

136 lines
3.8 KiB
Markdown
Raw Normal View History

2018-09-14 20:26:12 +00:00
# Protospace lockout authorization server
Provides an API to the web client and web server to serve tool data and authenticate users on tools.
## Setup
2018-09-12 06:21:26 +00:00
```
$ virtualenv -p python3 env
$ . env/bin/activate
(env) $ pip install -r requirements.txt
2018-09-14 00:04:02 +00:00
(env) $ python manage.py migrate --run-syncdb
2018-09-12 06:21:26 +00:00
(env) $ python manage.py createsuperuser --email admin@example.com --username admin
(env) $ python manage.py runserver
```
2018-09-14 20:26:12 +00:00
## API
2018-09-14 23:39:06 +00:00
The API is RESTful and returns hyperlinked json data. URLs require a trailing slash.
2018-09-14 20:26:12 +00:00
### For anonymous users
2018-09-14 23:39:06 +00:00
#### GET `/tooldata/`
2018-09-14 20:26:12 +00:00
Returns all the info about the shop and its tools. Tools are split into categories.
Example response:
```
{
"categories": [
{
"url": "http://127.0.0.1:8000/category/wood-shop/",
"tools": [
{
"url": "http://127.0.0.1:8000/tool/table-saw/",
"category": "http://127.0.0.1:8000/category/wood-shop/",
"name": "Table Saw",
"slug": "table-saw",
"info": "scary tool",
"wiki_id": 123,
"photo": "http://127.0.0.1:8000/media/floodgf.jpg"
},
{
"url": "http://127.0.0.1:8000/tool/jointer/",
"category": "http://127.0.0.1:8000/category/wood-shop/",
"name": "Jointer",
"slug": "jointer",
"info": "goes buzz buzz",
"wiki_id": 1,
"photo": "http://127.0.0.1:8000/media/uq4ldzsp4bu01.jpg"
}
],
"name": "Wood Shop",
"slug": "wood-shop",
"info": "protospace wood shop",
"photo": "http://127.0.0.1:8000/media/photo_2018-05-06_13-26-59.jpg"
},
{
"url": "http://127.0.0.1:8000/category/metal-shop/",
"tools": [
{
"url": "http://127.0.0.1:8000/tool/metal-lathe/",
"category": "http://127.0.0.1:8000/category/metal-shop/",
"name": "Metal Lathe",
"slug": "metal-lathe",
"info": "spins fast",
"wiki_id": 42,
"photo": "http://127.0.0.1:8000/media/intro-metal-shop-vali-steele-97.jpeg"
}
],
"name": "Metal Shop",
"slug": "metal-shop",
"info": "protospace metal shop",
"photo": "http://127.0.0.1:8000/media/photo_2018-05-08_17-57-02.jpg"
}
]
}
```
### For authenticated users
2018-09-14 23:39:06 +00:00
#### GET `/user/`
2018-09-14 20:26:12 +00:00
Returns info about the logged in user, including which tools they are authorized on. Note the top-level array (a quirk of django-rest-framework).
Example response:
```
[
{
"username": "admin",
"profile": {
"url": "http://127.0.0.1:8000/profile/1/",
"user": "admin",
"authorized_tools": [
"table-saw",
"jointer"
],
"lockout_admin": true
}
}
]
```
### For lockout admins
2018-09-14 20:36:57 +00:00
Ensure images are square and 1280x1280 px large. Slugs should be lowercase and one word (replace spaces with hyphens).
2018-09-14 20:26:12 +00:00
2018-09-14 23:39:06 +00:00
#### GET, POST `/tool/`
2018-09-14 20:26:12 +00:00
Get a list of tools, or post a new tool to the database.
2018-09-14 23:39:06 +00:00
#### GET, PUT, DELETE `/tool/[slug]/`
2018-09-14 20:26:12 +00:00
Get a specific tool, modify or delete an existing one.
2018-09-14 23:39:06 +00:00
#### GET, POST `/category/`
2018-09-14 20:26:12 +00:00
Get a list of categories, or post a new category to the database.
2018-09-14 23:39:06 +00:00
#### GET, PUT, DELETE `/category/[slug]/`
2018-09-14 20:26:12 +00:00
Get a specific category, modify or delete an existing one.
Note: you can only delete a category that has no tools.
2018-09-14 23:39:06 +00:00
#### GET `/profile/`
2018-09-14 20:26:12 +00:00
Get a list of all profiles.
2018-09-14 23:39:06 +00:00
#### GET, PUT `/profile/[id]/`
2018-09-14 20:26:12 +00:00
Get a specific profile, or modify an existing one.
Here you can authorize users on tools or make them another lockout admin.