Skip to content

Commit

Permalink
Merge 57b68d8 into 357b1f6
Browse files Browse the repository at this point in the history
  • Loading branch information
jirikuncar committed Dec 8, 2015
2 parents 357b1f6 + 57b68d8 commit 64ff7c2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
6 changes: 6 additions & 0 deletions invenio_oauthclient/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from .forms import EmailSignUpForm
from .models import RemoteAccount, RemoteToken
from .proxies import current_oauthclient
from .signals import account_info_received
from .utils import oauth_authenticate, oauth_get_user, oauth_register


Expand Down Expand Up @@ -217,6 +218,9 @@ def authorized_signup_handler(resp, remote, *args, **kwargs):
# ---------------
if not current_user.is_authenticated:
account_info = handlers['info'](resp)
account_info_received.send(
remote, response=resp, account_info=account_info
)

user = oauth_get_user(
remote.consumer_key,
Expand Down Expand Up @@ -258,6 +262,7 @@ def authorized_signup_handler(resp, remote, *args, **kwargs):
# -------------
if not token.remote_account.extra_data:
handlers['setup'](token, resp)
# TODO add signal for account setup

# Redirect to next
next_url = get_session_next_url(remote.name)
Expand Down Expand Up @@ -338,6 +343,7 @@ def signup_handler(remote, *args, **kwargs):

if not token.remote_account.extra_data:
handlers['setup'](token, response)
# TODO add signal for account setup

# Remove account info from session
session.pop(session_prefix + '_account_info', None)
Expand Down
48 changes: 48 additions & 0 deletions invenio_oauthclient/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2015 CERN.
#
# Invenio is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Invenio is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Invenio; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307, USA.
#
# In applying this license, CERN does not
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.

"""Signals used together with various handlers."""

from blinker import Namespace

_signals = Namespace()

account_info_received = _signals.signal('oauthclient-account-info-received')
"""Signal is sent after account info handler response.
Example subscriber:
.. code-block:: python
from invenio_oauthclient.signals import account_info_received
# During overlay initialization.
@account_info_received.connect_via(
sender=app.extensions['invenio-oauthclient'].handlers['orcid']
)
def load_extra_information(remote, response=None, account_info=None):
response = remote.get('https://example.org/api/resource')
# process response
"""
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
]

install_requires = [
'blinker>=1.4',
'cryptography>=0.6', # sqlalchemy-utils dependency
'Flask>=0.10.1',
'Flask-BabelEx>=0.9.2',
Expand Down

0 comments on commit 64ff7c2

Please sign in to comment.