grim/django-allauth-jetbrains-hub
Parents
Children
Initial revision, seems to be working fine in my test environment
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore Sat Jan 15 19:18:52 2022 -0600
@@ -0,0 +1,7 @@
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LICENSE Sat Jan 15 19:18:52 2022 -0600
@@ -0,0 +1,21 @@
+Copyright (c) 2022 Gary Kramlich +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md Sat Jan 15 19:18:52 2022 -0600
@@ -0,0 +1,65 @@
+# django-allauth-jetbrains-hub +Jetbrains Hub OAuth2 provider for django-allauth +* django-allauth (https://github.com/pennersr/django-allauth) +pip install django-allauth-jetbrains-hub +The server value in the path request must be set to point to your Jetbrains +hub instance and include the full path to it. For example, if your instance +is at https://example.com/ but you get redirected to https://example.com/hub/ +you should set server to https://example.com/hub/. + # The following apps are required: + 'django.contrib.sites', + 'allauth.socialaccount', + # Add allauth_microsoft to installed_apps + 'allauth_jetbrains_hub' +SOCIALACCOUNT_PROVIDERS = { + 'SERVER': 'https://example.com/hub/', +### Create service in your hub instance +* Create a service in your hub instance as documented [here](https://www.jetbrains.com/help/hub/add-service.html). +* Open the service in HUB. +* Set the Redirect URI to https://example.com/accounts/jetbrains-hub/login/callback/. +* Copy your Application ID and click change secret to get a new secret. +* Enter the Application ID and Secret into the Django Admin interface. +* Gary Kramlich <grim@reaperworld.com> +Forked from [github.com/schaenzer/django-allauth-microsoft](https://github.com/schaenzer/django-allauth-microsoft). --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/allauth_jetbrains_hub/provider.py Sat Jan 15 19:18:52 2022 -0600
@@ -0,0 +1,42 @@
+from allauth.socialaccount.providers.base import ProviderAccount +from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider +class JetbrainsHubAccount(ProviderAccount): + dflt = super(JetbrainsHubAccount, self).to_str() + return self.account.extra_data.get('name', dflt) +class JetbrainsHubProvider(OAuth2Provider): + account_class = JetbrainsHubAccount + def get_scope(self, request): + scope = set(super(JetbrainsHubProvider, self).get_scope(request)) + def get_default_scope(self): + def extract_uid(self, data): + return str(data['sub']) + def extract_common_fields(self, data): + first_name = data.get('name') + first_name, last_name = first_name.split(' ', 1) + email=data.get('email'), + username=data.get('email'), +provider_classes = [JetbrainsHubProvider] --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/allauth_jetbrains_hub/urls.py Sat Jan 15 19:18:52 2022 -0600
@@ -0,0 +1,4 @@
+from allauth.socialaccount.providers.oauth2.urls import default_urlpatterns +from .provider import JetbrainsHubProvider +urlpatterns = default_urlpatterns(JetbrainsHubProvider) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/allauth_jetbrains_hub/views.py Sat Jan 15 19:18:52 2022 -0600
@@ -0,0 +1,38 @@
+from allauth.socialaccount import app_settings +from allauth.socialaccount.providers.oauth2.views import ( +from .provider import JetbrainsHubProvider +class JetbrainsHubAuth2Adapter(OAuth2Adapter): + provider_id = JetbrainsHubProvider.id + settings = app_settings.PROVIDERS.get(provider_id, {}) + server = settings.get("SERVER") + # remove a trailing slash from the server. + authorize_url = f'{server}/api/rest/oauth2/auth' + access_token_url = f'{server}/api/rest/oauth2/token' + profile_url = f'{server}/api/rest/oauth2/userinfo' + def complete_login(self, request, app, token, **kwargs): + headers = {'Authorization': 'Bearer {0}'.format(token.token)} + resp = requests.get(self.profile_url, headers=headers) + extra_data = resp.json() + return self.get_provider().sociallogin_from_response( +oauth2_login = OAuth2LoginView.adapter_view(JetbrainsHubAuth2Adapter) +oauth2_callback = OAuth2CallbackView.adapter_view(JetbrainsHubAuth2Adapter) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/setup.py Sat Jan 15 19:18:52 2022 -0600
@@ -0,0 +1,17 @@
+from setuptools import setup, find_packages + name = "django-allauth-jetbrains-hub", + author = "Gary Kramlich", + author_email = "grim@reaperworld.com", + description = "Jetbrains Hub OAuth2 provider for django-allauth", + url = "https://keep.imfreedom.org/grim/django-allauth-jetbrains-hub", + packages=find_packages(), + install_requires=['django-allauth>=0.34.0'], + 'Programming Language :: Python', + 'Operating System :: OS Independent',