This repository was archived by the owner on Feb 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcustom_openid.py
More file actions
54 lines (47 loc) · 2.04 KB
/
custom_openid.py
File metadata and controls
54 lines (47 loc) · 2.04 KB
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
# This file is a part of github2fedmsg, a pubsubhubbub to zeromq bridge.
# Copyright (C) 2014, Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import velruse.api
import velruse.providers.openid as vr
from pyramid.security import NO_PERMISSION_REQUIRED
def add_openid_login(config, realm, identity_provider):
provider = SingleOpenIDConsumer(
'openid', 'openid',
realm=realm,
identity_provider=identity_provider,
storage=None,
)
login_path='/login/openid'
callback_path='/login/openid/callback'
config.add_route(provider.login_route, login_path)
config.add_view(provider, attr='login', route_name=provider.login_route,
permission=NO_PERMISSION_REQUIRED)
config.add_route(provider.callback_route, callback_path,
use_global_views=True,
factory=provider.callback)
velruse.api.register_provider(config, 'openid', provider)
class SingleOpenIDConsumer(vr.OpenIDConsumer):
def __init__(self,
name,
_type,
realm=None,
identity_provider=None,
storage=None,
context=vr.OpenIDAuthenticationComplete):
super(SingleOpenIDConsumer, self).__init__(
name, _type, realm, storage, context)
self.identity_provider = identity_provider
def _lookup_identifier(self, request, url):
return self.identity_provider