Skip to content

Commit

Permalink
Add OpenInfraOpenId backend (#753)
Browse files Browse the repository at this point in the history
Add a new backend that's functionally equivalent to the existing
OpenStackOpenId backend, but uses the id.openinfra.dev provider.
  • Loading branch information
ostackbrian authored and nijel committed Mar 15, 2023
1 parent 3fc92c0 commit 6408e00
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

- Backend for OpenInfra OpenID
- Facebook Limited Login backend

### Changed
Expand Down
49 changes: 49 additions & 0 deletions social_core/backends/openinfra.py
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

0 comments on commit 6408e00

Please sign in to comment.