@@ -100,3 +100,47 @@ You might want to completely bypass the authorization form, for instance if your
100100in-house product or if you already trust the application owner by other means. To this end, you have to
101101set ``skip_authorization = True `` on the ``Application `` model, either programmatically or within the
102102Django admin. Users will *not * be prompted for authorization, even on the first use of the application.
103+
104+
105+ .. _override-views :
106+
107+ Overriding views
108+ ================
109+
110+ You may want to override whole views from Django OAuth Toolkit, for instance if you want to
111+ change the login view for unregistred users depending on some query params.
112+
113+ In order to do that, you need to write a custom urlpatterns
114+
115+ .. code-block :: python
116+
117+ from django.urls import re_path
118+ from oauth2_provider import views as oauth2_views
119+ from oauth2_provider import urls
120+
121+ from .views import CustomeAuthorizationView
122+
123+
124+ app_name = " oauth2_provider"
125+
126+ urlpatterns = [
127+ # Base urls
128+ re_path(r " ^ authorize/" , CustomeAuthorizationView.as_view(), name = " authorize" ),
129+ re_path(r " ^ token/$ " , oauth2_views.TokenView.as_view(), name = " token" ),
130+ re_path(r " ^ revoke_token/$ " , oauth2_views.RevokeTokenView.as_view(), name = " revoke-token" ),
131+ re_path(r " ^ introspect/$ " , oauth2_views.IntrospectTokenView.as_view(), name = " introspect" ),
132+ ] + urls.management_urlpatterns + urls.oidc_urlpatterns
133+
134+ You can then remplace ``oauth2_provider.urls `` with the path to your urls file, but make sure you keep the
135+ same namespace as before.
136+
137+ .. code-block :: python
138+
139+ from django.urls import include, path
140+
141+ urlpatterns = [
142+ ...
143+ path(' o/' , include(' path.to.custom.urls' , namespace = ' oauth2_provider' )),
144+ ]
145+
146+ This method also allows to remove some of the urls (such as managements) urls if you don't want them.
0 commit comments