https://github.com/ericsopa/flask-api-key
Simple code to authenticate a POST to Flask
https://github.com/ericsopa/flask-api-key
Last synced: 4 months ago
JSON representation
Simple code to authenticate a POST to Flask
- Host: GitHub
- URL: https://github.com/ericsopa/flask-api-key
- Owner: ericsopa
- Created: 2016-10-20T22:32:04.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-02-14T08:28:50.000Z (about 4 years ago)
- Last Synced: 2024-08-14T07:08:55.390Z (8 months ago)
- Language: Python
- Size: 6.84 KB
- Stars: 54
- Watchers: 3
- Forks: 14
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- jimsghstars - ericsopa/flask-api-key - Simple code to authenticate a POST to Flask (Python)
README
# flask-api-key
Simple API Key authN using decarators via HTTPS using TLS.This is a proof of concept (POC) of a RESTful end point using Flask.
Flask uses TLS for HTTPS connections.
Sample self-signed certs and keys are provided.
As writen, you can send a GET and POST.The POST is authenticated using an API Key as a parameter.
Where the key is stored in a file, so the key value is not stored in code.
Be sure to change the value in api.key when deploying.##Installation
####Dependencies
1. Python 2 or 3
2. Flask
3. virtualenv####Setup
```
$ cd flask-api-key
$ virtualenv venv
$ . venv/bin/activate
$ export FLASK_APP=goaway.py
$ flask run
* Running on https://127.0.0.1:443/ (Press CTRL+C to quit)
```##GET Test
```
curl -k https://127.0.0.1
Hellow world!
```
Flask server output:
```
127.0.0.1 - - [23/Oct/2016 14:55:55] "GET / HTTP/1.1" 200 -
```##POST Tests
###Key in header
```
$ curl -k -H "Content-Type: application/json" -H "x-api-key: eiWee8ep9due4deeshoa8Peichai8Ei2" -X POST -d '{"username":"xyz","password":"xyz"}' https://127.0.0.1/json/
Posted JSON!
```
Flask server output:
```
127.0.0.1 - - [23/Oct/2016 14:55:26] "POST /json/ HTTP/1.1" 200 -
```###Key in argument
```
curl -k -H "Content-Type: application/json" -X POST -d '{"username":"xyz","password":"xyz"}' https://127.0.0.1/json/?key=eiWee8ep9due4deeshoa8Peichai8Ei2
Posted JSON!
```
Flask server output:
```
127.0.0.1 - - [23/Oct/2016 14:55:26] "POST /json/?key=eiWee8ep9due4deeshoa8Peich
ai8Eih HTTP/1.1" 200 -
```