Created
April 16, 2019 15:40
-
-
Save gene1wood/f0f827cd72dde3ec7a83abd16ef51d97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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