sources/oauth: fix reddit (#5557)

This commit is contained in:
Jens L 2023-05-09 23:41:24 +02:00 committed by GitHub
parent 8ccdbdc370
commit b5b1ed5887
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 8 deletions

View File

@ -217,6 +217,15 @@ class OktaOAuthSource(OAuthSource):
verbose_name_plural = _("Okta OAuth Sources") verbose_name_plural = _("Okta OAuth Sources")
class RedditOAuthSource(OAuthSource):
"""Social Login using reddit.com."""
class Meta:
abstract = True
verbose_name = _("Reddit OAuth Source")
verbose_name_plural = _("Reddit OAuth Sources")
class UserOAuthSourceConnection(UserSourceConnection): class UserOAuthSourceConnection(UserSourceConnection):
"""Authorized remote OAuth provider.""" """Authorized remote OAuth provider."""

View File

@ -3,7 +3,7 @@ from typing import Any
from requests.auth import HTTPBasicAuth from requests.auth import HTTPBasicAuth
from authentik.sources.oauth.clients.oauth2 import OAuth2Client from authentik.sources.oauth.clients.oauth2 import UserprofileHeaderAuthClient
from authentik.sources.oauth.types.registry import SourceType, registry from authentik.sources.oauth.types.registry import SourceType, registry
from authentik.sources.oauth.views.callback import OAuthCallback from authentik.sources.oauth.views.callback import OAuthCallback
from authentik.sources.oauth.views.redirect import OAuthRedirect from authentik.sources.oauth.views.redirect import OAuthRedirect
@ -14,12 +14,12 @@ class RedditOAuthRedirect(OAuthRedirect):
def get_additional_parameters(self, source): # pragma: no cover def get_additional_parameters(self, source): # pragma: no cover
return { return {
"scope": ["identity"], "scope": "identity",
"duration": "permanent", "duration": "permanent",
} }
class RedditOAuth2Client(OAuth2Client): class RedditOAuth2Client(UserprofileHeaderAuthClient):
"""Reddit OAuth2 Client""" """Reddit OAuth2 Client"""
def get_access_token(self, **request_kwargs): def get_access_token(self, **request_kwargs):
@ -37,6 +37,7 @@ class RedditOAuth2Callback(OAuthCallback):
self, self,
info: dict[str, Any], info: dict[str, Any],
) -> dict[str, Any]: ) -> dict[str, Any]:
print(info)
return { return {
"username": info.get("name"), "username": info.get("name"),
"email": None, "email": None,
@ -51,9 +52,9 @@ class RedditType(SourceType):
callback_view = RedditOAuth2Callback callback_view = RedditOAuth2Callback
redirect_view = RedditOAuthRedirect redirect_view = RedditOAuthRedirect
name = "reddit" name = "Reddit"
slug = "reddit" slug = "reddit"
authorization_url = "https://accounts.google.com/o/oauth2/auth" authorization_url = "https://www.reddit.com/api/v1/authorize"
access_token_url = "https://accounts.google.com/o/oauth2/token" # nosec access_token_url = "https://www.reddit.com/api/v1/access_token" # nosec
profile_url = "https://www.googleapis.com/oauth2/v1/userinfo" profile_url = "https://oauth.reddit.com/api/v1/me"

View File

@ -38507,7 +38507,7 @@ components:
* `openidconnect` - OpenID Connect * `openidconnect` - OpenID Connect
* `okta` - Okta * `okta` - Okta
* `patreon` - Patreon * `patreon` - Patreon
* `reddit` - reddit * `reddit` - Reddit
* `twitch` - Twitch * `twitch` - Twitch
* `twitter` - Twitter * `twitter` - Twitter
ProxyMode: ProxyMode:

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="1000px" height="1000px" viewBox="-194 -104 1000 1000" enable-background="new -194 -104 1000 1000" xml:space="preserve">
<g id="Artwork">
<g>
<circle fill="#FF4500" cx="306" cy="396" r="500"/>
<path fill="#FFFFFF" d="M639.332,396c0-40.351-32.746-73.099-73.101-73.099c-19.88,0-37.425,7.603-50.292,20.467
c-49.705-35.673-118.714-59.065-194.735-61.988l33.333-156.141l108.188,22.809c1.168,27.484,23.976,49.707,52.047,49.707
c28.654,0,52.046-23.392,52.046-52.047c0-28.654-23.392-52.046-52.046-52.046c-20.471,0-38.013,11.696-46.2,29.24L347.521,97.169
c-3.509-0.585-7.017,0-9.941,1.754s-4.68,4.679-5.85,8.188l-36.841,174.269c-77.778,2.339-147.368,25.146-197.66,61.988
C84.362,331.086,66.232,322.9,46.935,322.9c-40.351,0-73.099,32.749-73.099,73.099c0,29.825,17.544,54.971,43.275,66.667
c-1.17,7.017-1.754,14.62-1.754,22.221c0,112.28,130.408,202.924,291.813,202.924c161.402,0,291.812-90.644,291.812-202.924
c0-7.601-0.583-14.62-1.754-21.638C621.203,451.555,639.332,425.824,639.332,396z M139.333,448.046
c0-28.654,23.392-52.046,52.046-52.046c28.655,0,52.046,23.392,52.046,52.046s-23.392,52.047-52.046,52.047
C162.725,500.093,139.333,476.7,139.333,448.046z M429.976,585.473c-35.671,35.675-103.509,38.013-123.393,38.013
c-19.882,0-88.303-2.925-123.391-38.013c-5.263-5.263-5.263-14.034,0-19.297c5.265-5.263,14.036-5.263,19.298,0
c22.223,22.222,70.176,30.409,104.68,30.409c34.501,0,81.872-8.188,104.677-30.409c5.263-5.263,14.037-5.263,19.3,0
C435.238,572.022,435.238,580.21,429.976,585.473z M420.618,500.093c-28.655,0-52.047-23.393-52.047-52.047
S391.963,396,420.618,396c28.657,0,52.05,23.392,52.05,52.046S449.275,500.093,420.618,500.093z"/>
</g>
</g>
<g id="Spacing_Guide" display="none">
<rect y="90" display="inline" fill="none" stroke="#D8D8D8" stroke-width="0.5" stroke-miterlimit="10" width="152.911" height="152.911"/>
<rect y="90" display="inline" fill="none" stroke="#D8D8D8" stroke-width="0.5" stroke-miterlimit="10" width="612" height="152.911"/>
<rect y="548.91" display="inline" fill="none" stroke="#D8D8D8" stroke-width="0.5" stroke-miterlimit="10" width="612" height="152.911"/>
<rect y="90" display="inline" fill="none" stroke="#D8D8D8" stroke-width="0.5" stroke-miterlimit="10" width="152.911" height="612"/>
<rect x="459.09" y="90" display="inline" fill="none" stroke="#D8D8D8" stroke-width="0.5" stroke-miterlimit="10" width="152.91" height="612"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.8 KiB