Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_diagnosis_info: additional info about authomatic.login() #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions authomatic/extras/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-

def get_diagnosis_info(result):
"""
Get additional info about login.

:attr result:
= authomatic.login().
"""
res = None
# check email possibility for Facebook
if result.provider.name == "facebook":
provider = result.provider
perm_url = provider.user_info_url + "/permissions"
response = provider._fetch(perm_url, params={'access_token': provider.credentials.token})

res = {
"perm_url": perm_url,
"status": response.status,
#"content": response.content
"content": response.data
}

return res
7 changes: 6 additions & 1 deletion examples/gae/showcase/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import webapp2
from authomatic import Authomatic
from authomatic.adapters import Webapp2Adapter
from authomatic.extras import get_diagnosis_info

if 'development' in os.environ['SERVER_SOFTWARE'].lower():
import config
Expand Down Expand Up @@ -53,14 +54,18 @@ class Home(BaseHandler):
def get(self):
render(self)


class Login(BaseHandler):
def any(self, provider_name):
result = authomatic.login(Webapp2Adapter(self), provider_name)
if result:
apis = []
if result.user:
result.user.update()

diagnosis = get_diagnosis_info(result)
if diagnosis:
logging.info('More info: %s' % diagnosis)

if result.user.credentials:
apis = config.config.get(provider_name, {}).get('_apis', {})

Expand Down