EagleEyev3/server.py

43 lines
1.2 KiB
Python
Raw Normal View History

2023-05-18 15:40:02 +00:00
import json, requests
from flask import Flask, request
from EagleEyev3 import EagleEyev3
2023-05-18 15:40:02 +00:00
een = EagleEyev3()
app = Flask(__name__)
@app.route('/')
def index():
# This is getting the ?code= querystring value from the HTTP request.
code = request.args.get('code')
2023-07-03 20:25:19 +00:00
# this is here until api_support updates to use the /login_callback
if (code):
oauth_object = een.login_tokens(code)
return oauth_object
#return f"Hello {een.current_user['firstName']} {een.current_user['lastName']}"
base_url = "https://auth.eagleeyenetworks.com/oauth2/authorize"
path_url = f"?client_id={een.client_id}&response_type=code&scope=vms.all&redirect_uri={een.redirect_uri}"
request_auth_url = f"{base_url}{path_url}"
return "<a href='"+request_auth_url+"'>Login with Eagle Eye Networks</a>"
2023-07-03 20:25:19 +00:00
# @app.route('/login_callback')
# def login_callback():
# # This is getting the ?code= querystring value from the HTTP request.
# code = request.args.get('code')
# if (code):
# oauth_object = een.login_tokens(code)
# return f"Hello {een.current_user['firstName']} {een.current_user['lastName']}"
2023-05-18 15:40:02 +00:00
if __name__ == '__main__':
app.run(host=een.server_host, port=een.server_port)