Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Demo] Add a simple oauth implementation via django-oauth-toolkit #447

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions oioioi/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
'oioioi.quizzes',
'oioioi._locale',
'oioioi.interactive',
'oioioi.oauth',

'djsupervisor',
'registration',
Expand Down Expand Up @@ -313,6 +314,7 @@

'nested_admin',
'coreapi',
'oauth2_provider',
'rest_framework',
'rest_framework.authtoken',

Expand Down Expand Up @@ -845,6 +847,7 @@
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
),
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'
}
Expand Down
Empty file added oioioi/oauth/__init__.py
Empty file.
33 changes: 33 additions & 0 deletions oioioi/oauth/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import oauth2_provider.views as oauth2_views
from django.conf import settings
from django.contrib import admin as django_admin
from django.views import i18n
from django.urls import include, re_path

app_name = 'oauth'

oauth2_endpoint_views = [
re_path(r'^authorize/', oauth2_views.AuthorizationView.as_view(), name="authorize"),
re_path(r'^token/', oauth2_views.TokenView.as_view(), name="token"),
re_path(r'^revoke-token/', oauth2_views.RevokeTokenView.as_view(), name="revoke-token"),
]

if settings.DEBUG:
# OAuth2 Application Management endpoints
oauth2_endpoint_views += [
re_path(r'^applications/', oauth2_views.ApplicationList.as_view(), name="list"),
re_path(r'^applications/register/', oauth2_views.ApplicationRegistration.as_view(), name="register"),
re_path(r'^applications/<pk>/', oauth2_views.ApplicationDetail.as_view(), name="detail"),
re_path(r'^applications/<pk>/delete/', oauth2_views.ApplicationDelete.as_view(), name="delete"),
re_path(r'^applications/<pk>/update/', oauth2_views.ApplicationUpdate.as_view(), name="update"),
]

oauth2_endpoint_views += [
re_path(r'^authorized-tokens/', oauth2_views.AuthorizedTokensListView.as_view(), name="authorized-token-list"),
re_path(r'^authorized-tokens/<pk>/delete/', oauth2_views.AuthorizedTokenDeleteView.as_view(),
name="authorized-token-delete"),
]

urlpatterns = [
re_path(r'^o/', include((oauth2_endpoint_views, 'oauth2_provider'), namespace="oauth2_provider")),
]
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"django-debug-toolbar",
"django-extensions>=3.2,<3.3",
"djangorestframework>=3.14,<3.15",
"django-oauth-toolkit>=3.0,<3.1",
"Werkzeug",
"pytest>=7.2,<8.0",
"pytest-cov>=4.0,<5.0",
Expand Down
Loading