Skip to content

Instantly share code, notes, and snippets.

@gene1wood
Created April 16, 2019 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gene1wood/f0f827cd72dde3ec7a83abd16ef51d97 to your computer and use it in GitHub Desktop.
Save gene1wood/f0f827cd72dde3ec7a83abd16ef51d97 to your computer and use it in GitHub Desktop.
from authlib.flask.client import OAuth
if os.getenv("NO_AUTH", "False") == "False":
AUTH0_CALLBACK_URL = env.get(constants.AUTH0_CALLBACK_URL)
AUTH0_CLIENT_ID = env.get(constants.AUTH0_CLIENT_ID)
AUTH0_CLIENT_SECRET = env.get(constants.AUTH0_CLIENT_SECRET)
AUTH0_DOMAIN = env.get(constants.AUTH0_DOMAIN)
AUTH0_BASE_URL = "https://" + AUTH0_DOMAIN
AUTH0_AUDIENCE = env.get(constants.AUTH0_AUDIENCE)
if AUTH0_AUDIENCE is "":
AUTH0_AUDIENCE = AUTH0_BASE_URL + "/userinfo"
oauth = OAuth(app)
auth0 = oauth.register(
"auth0",
client_id=AUTH0_CLIENT_ID,
client_secret=AUTH0_CLIENT_SECRET,
api_base_url=AUTH0_BASE_URL,
access_token_url=AUTH0_BASE_URL + "/oauth/token",
authorize_url=AUTH0_BASE_URL + "/authorize",
client_kwargs={"scope": "openid profile"},
)
def requires_auth(f):
@wraps(f)
def decorated(*args, **kwargs):
if os.getenv("NO_AUTH", "False") == "True":
return f(*args, **kwargs)
if constants.PROFILE_KEY not in session:
return redirect("/login")
return f(*args, **kwargs)
return decorated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment