Skip to content

Commit a456cd2

Browse files
committed
update readme and completed auth flask apps
1 parent 5e39001 commit a456cd2

35 files changed

+18802
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,4 @@ monitor-django-apps/djmonitor/db.sqlite3
9898
# Flask auth Okta post
9999
flask-auth-okta/openidconnect_secrets.json
100100
flask-auth-okta/.env
101+
auth-existing-flask-app/completed/openidconnect_secrets.json

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Posts and associated code:
77

88
|Post|Code Directory|
99
|---|---|
10+
|[Fresh Tutorials on Full Stack Python](https://www.fullstackpython.com/blog/fresh-tutorials-october-2018.html)|No code in post.|
11+
|[How to Provision Ubuntu 18.04 LTS Linux Servers on DigitalOcean](https://www.fullstackpython.com/blog/provision-ubuntu-1804-linux-servers-digitalocean.html)|No code in post.|
1012
|[How to Add User Authentication to Flask Apps with Okta](https://www.fullstackpython.com/blog/add-user-authentication-flask-apps-okta.html)|[flask-auth-okta](./flask-auth-okta)|
1113
|[Running Bottle Apps in Docker Containers on macOS](https://www.fullstackpython.com/blog/first-steps-bottle-web-apps-docker-containers.html)|[docker-bottle-mac](./docker-bottle-mac)|
1214
|[How to Add Maps to Django Web App Projects with Mapbox](https://www.fullstackpython.com/blog/maps-django-web-applications-projects-mapbox.html)|[maps-django-mapbox](./maps-django-mapbox)|
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import redis
2+
from os import environ
3+
from flask import Flask
4+
from app.utils import make_celery
5+
from config import Config
6+
from flask_sqlalchemy import SQLAlchemy
7+
from flask_migrate import Migrate
8+
from flask_oidc import OpenIDConnect
9+
from okta import UsersClient
10+
11+
12+
app = Flask(__name__, static_url_path='/static')
13+
app.config.from_object(Config)
14+
db = SQLAlchemy(app)
15+
migrate = Migrate(app, db)
16+
17+
# connect to Redis instance
18+
redis_db = redis.StrictRedis(host=app.config['REDIS_SERVER'],
19+
port=app.config['REDIS_PORT'],
20+
db=app.config['REDIS_DB'])
21+
celery = make_celery(app)
22+
23+
24+
# instantiate OpenID client to handle user session
25+
oidc = OpenIDConnect(app)
26+
# Okta client will determine if a user has an appropriate account
27+
okta_client = UsersClient(environ.get("OKTA_ORG_URL"),
28+
environ.get("OKTA_AUTH_TOKEN"))
29+
30+
31+
from app import routes

auth-existing-flask-app/completed/app/models.py

Whitespace-only changes.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from flask import send_from_directory, render_template
2+
from flask import redirect, g
3+
from app import app, oidc, okta_client
4+
5+
6+
@app.before_request
7+
def before_request():
8+
if oidc.user_loggedin:
9+
g.user = okta_client.get_user(oidc.user_getfield("sub"))
10+
else:
11+
g.user = None
12+
13+
14+
@app.route('/js/<path:path>')
15+
def send_js(path):
16+
return send_from_directory('js', path)
17+
18+
19+
@app.route('/css/<path:path>')
20+
def send_css(path):
21+
return send_from_directory('css', path)
22+
23+
24+
@app.route("/")
25+
def dashboard():
26+
return render_template('dashboard.html')
27+
28+
29+
@app.route("/repositories")
30+
@oidc.require_login
31+
def repositories():
32+
return render_template('repositories.html')
33+
34+
35+
@app.route("/login")
36+
@oidc.require_login
37+
def login():
38+
return redirect(url_for(".repositories"))
39+
40+
41+
@app.route("/logout")
42+
def logout():
43+
oidc.logout()
44+
return redirect(url_for(".landing_page"))

0 commit comments

Comments
 (0)