dashboard/areas/auth/auth.py
2022-01-18 09:48:18 +00:00

26 lines
666 B
Python

from flask import jsonify
from flask_jwt_extended import create_access_token
from flask_cors import cross_origin
from datetime import timedelta
from areas import api_v1
from config import *
from helpers import HydraOauth
@api_v1.route("/login", methods=["POST"])
@cross_origin()
def login():
authorization_url = HydraOauth.authorize()
return jsonify({"authorizationUrl": authorization_url})
@api_v1.route("/hydra/callback")
@cross_origin()
def hydra_callback():
token = HydraOauth.get_token()
access_token = create_access_token(
identity=token, expires_delta=timedelta(days=365)
)
return jsonify({"access_token": access_token})