-
Notifications
You must be signed in to change notification settings - Fork 5
/
esgfopenid.py
62 lines (47 loc) · 2.08 KB
/
esgfopenid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""
|openid| Providers
----------------------------------
Providers which implement the |openid|_ protocol based on the
`python-openid`_ library.
.. warning::
This providers are dependent on the |python-openid|_ package.
"""
import ssl
from six.moves.urllib.request import urlopen
from authomatic.providers.openid import OpenID
# noinspection PyProtectedMember, PyUnresolvedReferences
from openid.fetchers import Urllib2Fetcher # , setDefaultFetcher
from magpie.common import get_logger
LOGGER = get_logger(__name__)
__all__ = ['ESGFOpenID']
class MyFetcher(Urllib2Fetcher):
@staticmethod
def urlopen(req):
# noinspection PyProtectedMember
return urlopen(req, context=ssl._create_unverified_context())
class ESGFOpenID(OpenID):
"""
ESGF - Earth System Grid Federation
:class:`authomatic.providers.openid.OpenID` provider with a common provider url template :
``https://{hostname}/{provider}-idp/idp/{username}``.
"""
def __init__(self, *args, **kwargs):
"""
Accepts additional keyword arguments:
:param hostname:
The hostname of the ESGF OpenID provider. Default: localhost
:param provider_url:
The provider identifier url template. Default: https://{hostname}/{provider}-idp/idp/{username}
"""
super(ESGFOpenID, self).__init__(*args, **kwargs)
self.hostname = self._kwarg(kwargs, 'hostname', 'localhost')
self.provider_url = self._kwarg(kwargs, 'provider_url', 'https://{hostname}/providers-idp/openid/{username}')
# if username is given set provider identifier using the provider url
if 'username' in self.params:
self.username = self.params.get('username')
self.identifier = self.provider_url.format(hostname=self.hostname, username=self.username)
# use fetcher with disabled ssl verification
# setDefaultFetcher(MyFetcher())
# Authomatic provider type ID is generated from this list's indexes!
# Always append new providers at the end so that ids of existing providers don't change!
PROVIDER_ID_MAP = [ESGFOpenID]