2018-04-18 16:46:53 -04:00
|
|
|
from flask_restful import Resource
|
|
|
|
from flask import request, jsonify
|
|
|
|
from flask_jwt_extended import create_access_token
|
|
|
|
from master import app, ctx
|
2018-04-19 01:48:14 -04:00
|
|
|
import datetime
|
2018-04-18 16:46:53 -04:00
|
|
|
|
|
|
|
|
|
|
|
class Authenticate(Resource):
|
|
|
|
def post(self):
|
|
|
|
instance_id = request.json['id']
|
|
|
|
if ctx.get_token(instance_id) is not False:
|
|
|
|
return { 'message' : 'that id already has a token'}, 401
|
|
|
|
else:
|
2018-04-19 01:48:14 -04:00
|
|
|
expires = datetime.timedelta(days=1)
|
|
|
|
token = create_access_token(instance_id, expires_delta=expires)
|
2018-04-18 16:46:53 -04:00
|
|
|
ctx.add_token(instance_id, token)
|
|
|
|
return { 'access_token' : token }, 200
|