Skip to content

Commit

Permalink
oauthclient: adds SSO with CERN-oauth service inveniosoftware#2
Browse files Browse the repository at this point in the history
  • Loading branch information
Pamfilos Fokianos committed Feb 25, 2015
1 parent bba5230 commit 717061f
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions invenio/modules/oauthclient/contrib/cern.py
Expand Up @@ -73,7 +73,7 @@
"""

import copy
import copy, re
import requests
from flask import session, current_app
from invenio.ext.sqlalchemy import db
Expand Down Expand Up @@ -111,6 +111,9 @@
re.compile(r'Users by Home CERNHOME[A-Z]'),
)

CFG_EXTERNAL_AUTH_TOKEN_PARAM_RESOURCE =
current_app.config.get('CFG_EXTERNAL_AUTH_TOKEN_PARAM_RESOURCE')

REMOTE_APP = dict(
title="CERN",
description="Connecting to CERN Organization.",
Expand All @@ -126,7 +129,7 @@
),
params=dict(
request_token_params={
"resource": app.config.get('CFG_EXTERNAL_AUTH_TOKEN_PARAM_RESOURCE')
"resource": current_app.config.get('CFG_EXTERNAL_AUTH_TOKEN_PARAM_RESOURCE')
},
base_url="https://oauth.web.cern.ch/",
request_token_url=None,
Expand All @@ -149,18 +152,19 @@
))

def fetch_groups(groups):
groups = [group for group in groups if group not in app.config.get(
groups = [group for group in groups if group not in current_app.config.get(
'CFG_EXTERNAL_AUTH_HIDDEN_GROUPS',
CFG_EXTERNAL_AUTH_HIDDEN_GROUPS)]
for regexp in app.config.get('CFG_EXTERNAL_AUTH_HIDDEN_GROUPS_RE',
for regexp in current_app.config.get('CFG_EXTERNAL_AUTH_HIDDEN_GROUPS_RE',
CFG_EXTERNAL_AUTH_HIDDEN_GROUPS_RE):
for group in groups:
if regexp.match(group):
groups.remove(group)
groups.remove(group)

return dict(map(lambda x: (x, '@' in x and x + ' (Mailing list)'
or x + ' (Group)'), groups)
or x + ' (Group)'), groups))

def get_dict_form_response(response):
def get_dict_from_response(response):
result = {}
for i in response.json():
k = str(i['Type'])
Expand All @@ -172,7 +176,6 @@ def get_dict_form_response(response):

def account_info(remote, resp):
"""Retrieve remote account information used to find local user."""
from flask import current_app
current_app.logger.info(remote)
current_app.logger.info(resp)

Expand Down

0 comments on commit 717061f

Please sign in to comment.