-
-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new backend that's functionally equivalent to the existing OpenStackOpenId backend, but uses the id.openinfra.dev provider.
- Loading branch information
1 parent
3fc92c0
commit 6408e00
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
""" | ||
OpenInfra OpenId backend | ||
""" | ||
from urllib.parse import urlsplit | ||
|
||
from openid.extensions import ax | ||
|
||
from .open_id import OpenIdAuth | ||
|
||
|
||
class OpenInfraOpenId(OpenIdAuth): | ||
name = "openinfra" | ||
URL = "id.openinfra.dev" | ||
|
||
def get_user_details(self, response): | ||
"""Generate username from identity url""" | ||
values = super().get_user_details(response) | ||
values["username"] = values.get("username") or urlsplit( | ||
response.identity_url | ||
).path.strip("/") | ||
values["nickname"] = values.get("nickname", "") | ||
return values | ||
|
||
def setup_request(self, params=None): | ||
"""Fetch email, firstname, lastname from openid""" | ||
request = self.openid_request(params) | ||
|
||
# TODO: use sreg instead ax request to fetch nickname as username | ||
fetch_request = ax.FetchRequest() | ||
fetch_request.add( | ||
ax.AttrInfo( | ||
"http://axschema.org/contact/email", alias="email", required=True | ||
) | ||
) | ||
|
||
fetch_request.add( | ||
ax.AttrInfo( | ||
"http://axschema.org/namePerson/first", alias="firstname", required=True | ||
) | ||
) | ||
|
||
fetch_request.add( | ||
ax.AttrInfo( | ||
"http://axschema.org/namePerson/last", alias="lastname", required=True | ||
) | ||
) | ||
|
||
request.addExtension(fetch_request) | ||
return request |