We're getting closer to getting auth to work.
pull/6/head
Hailey Clark 6 years ago
parent 21e9f92e85
commit a4487b58e6
  1. 18
      app-ajax.py
  2. 36
      apptest.py
  3. 31
      google_auth.py

@ -6,13 +6,22 @@ import pprint
import configparser import configparser
import json import json
import appdb, appsms import appdb, appsms
from flask import Flask, render_template, request #from flask import Flask, render_template, request
import flask
from authlib.client import OAuth2Session
import google.oauth2.credentials
import googleapiclient.discovery
import google_auth
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read('config.ini') config.read('config.ini')
app_debug = config.get("app","debug") app_debug = config.get("app","debug")
app = Flask(__name__) app = flask.Flask(__name__)
app.secret_key = config.get("auth","FN_FLASK_SECRET_KEY")
app.register_blueprint(google_auth.app)
if app_debug == '1': if app_debug == '1':
app.debug = True app.debug = True
else: else:
@ -20,7 +29,10 @@ else:
@app.route('/') @app.route('/')
def index(): def index():
return render_template('index.html') if google_auth.is_logged_in():
user_info = google_auth.get_user_info()
return '<div>You are currently logged in as ' + user_info['given_name'] + '<div><pre>' + json.dumps(user_info, indent=4) + "</pre>"
return 'You are not currently logged in.'
@app.route('/single/<int:number>', methods=['GET']) @app.route('/single/<int:number>', methods=['GET'])
def manageSingleSMS(number): def manageSingleSMS(number):

@ -0,0 +1,36 @@
import functools
import json
import os
import configparser
import flask
from authlib.client import OAuth2Session
import google.oauth2.credentials
import googleapiclient.discovery
import google_auth
config = configparser.ConfigParser()
config.read('config.ini')
app_debug = config.get("app","debug")
app = flask.Flask(__name__)
app.secret_key = config.get("auth","FN_FLASK_SECRET_KEY")
app.register_blueprint(google_auth.app)
@app.route('/')
def index():
if google_auth.is_logged_in():
user_info = google_auth.get_user_info()
return '<div>You are currently logged in as ' + user_info['given_name'] + '<div><pre>' + json.dumps(user_info, indent=4) + "</pre>"
return 'You are not currently logged in.'
if __name__ == '__main__':
app.run(
host="0.0.0.0",
port=int("8020")
)

@ -5,7 +5,8 @@
import functools import functools
import os import os
from flask import Flask, request, session, render_template, flash #from flask import Flask, request, session, render_template, flash
import flask
import configparser import configparser
from authlib.client import OAuth2Session from authlib.client import OAuth2Session
import google.oauth2.credentials import google.oauth2.credentials
@ -25,21 +26,18 @@ BASE_URI = config.get("auth","FN_BASE_URI")
CLIENT_ID = config.get("auth","FN_CLIENT_ID") CLIENT_ID = config.get("auth","FN_CLIENT_ID")
CLIENT_SECRET = config.get("auth","FN_CLIENT_SECRET") CLIENT_SECRET = config.get("auth","FN_CLIENT_SECRET")
#FN_FLASK_SECRET_KEY
AUTH_TOKEN_KEY = 'auth_token' AUTH_TOKEN_KEY = 'auth_token'
AUTH_STATE_KEY = 'auth_state' AUTH_STATE_KEY = 'auth_state'
#app = Flask.Blueprint('google_auth', __name__) app = flask.Blueprint('google_auth', __name__)
app = flask.Flask(__name__) #app = flask.Flask(__name__)
if app_debug == '1': #if app_debug == '1':
app.debug = True app.debug = True
else: ##else:
app.debug = False #app.debug = False
if __name__ == '__main__':
app.run(
host="0.0.0.0",
port=int("8020")
)
def is_logged_in(): def is_logged_in():
return True if AUTH_TOKEN_KEY in flask.session else False return True if AUTH_TOKEN_KEY in flask.session else False
@ -69,7 +67,7 @@ def get_user_info():
def no_cache(view): def no_cache(view):
@functools.wraps(view) @functools.wraps(view)
def no_cache_impl(*args, **kwargs): def no_cache_impl(*args, **kwargs):
response = app.make_response(view(*args, **kwargs)) response = flask.make_response(view(*args, **kwargs))
response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0' response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'
response.headers['Pragma'] = 'no-cache' response.headers['Pragma'] = 'no-cache'
response.headers['Expires'] = '-1' response.headers['Expires'] = '-1'
@ -120,3 +118,10 @@ def logout():
flask.session.pop(AUTH_STATE_KEY, None) flask.session.pop(AUTH_STATE_KEY, None)
return flask.redirect(BASE_URI, code=302) return flask.redirect(BASE_URI, code=302)
if __name__ == '__main__':
app.run(
host="0.0.0.0",
port=int("8020")
)
Loading…
Cancel
Save