Skip to content

Commit

Permalink
Log user profile object from google
Browse files Browse the repository at this point in the history
  • Loading branch information
radeklos committed Dec 15, 2015
1 parent 07b9449 commit 02be62b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
3 changes: 3 additions & 0 deletions fm/app.py
Expand Up @@ -20,6 +20,7 @@
from fm import http
from fm.ext import celery, db, redis, via
from fm.http.cors import CORS
import fm.logs


def configure(app, config=None):
Expand Down Expand Up @@ -128,6 +129,8 @@ def create(config=None):
# Error Handling
errors(app)

fm.logs.configure(app)

@app.before_request
def require_json():
""" Ensures the API only supports JSON in.
Expand Down
39 changes: 39 additions & 0 deletions fm/logs.py
@@ -0,0 +1,39 @@
# Standard Libs
import logging


# Default Logging Configuration
DEFAULT_LOG_LEVEL = 'INFO'
DEFAULT_LOG_FORMAT = "%(levelname)s [%(asctime)s]: %(message)s"


def configure(app):
"""Configures logging for the Flask Application.
Arguments
---------
app : flask.app.Flask
Flask application instance
"""

# Reset the handlers
app.logger.handlers = []

# Setup Stream Handler
handler = logging.StreamHandler()
# Set Format
try:
handler.setFormatter(logging.Formatter(app.config['LOG_FORMAT']))
except KeyError:
handler.setFormatter(logging.Formatter(DEFAULT_LOG_FORMAT))

# Set Level
try:
level_name = app.config['LOG_LEVEL']
except KeyError:
level_name = DEFAULT_LOG_LEVEL

level = getattr(logging, level_name.upper(), logging.INFO)

# Update the app logger
app.logger.setLevel(level)
app.logger.addHandler(handler)
5 changes: 3 additions & 2 deletions fm/oauth2/google.py
Expand Up @@ -14,6 +14,7 @@

# First Party Libs
from fm.ext import config
from flask import current_app


class GoogleOAuth2Exception(Exception):
Expand Down Expand Up @@ -131,8 +132,8 @@ def authenticate_oauth_code(code):
credentials = get_credentials(code)
user = user_from_credentials(credentials)

if not user['domain'] in config.GOOGLE_ALLOWED_DOMAINS:
disconnect(credentials.access_token)
current_app.logger.info('[Google auth] user profile {}'.format(user))
if not user.get('domain') in config.GOOGLE_ALLOWED_DOMAINS:
raise GoogleOAuth2Exception('You need be a member of SOON_ or This Here')

return user, credentials

0 comments on commit 02be62b

Please sign in to comment.