django-oauth-toolkit | OAuth2 goodies for the Djangonauts | OAuth library
kandi X-RAY | django-oauth-toolkit Summary
kandi X-RAY | django-oauth-toolkit Summary
OAuth2 goodies for the Djangonauts!
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Handle GET request
- Called when an error is received
- Redirect to an OAuth2 response
- Redirect to login
- Handle GET requests
- Gets the claims for the given request
- Returns the claims for the given request
- Render the application
- Clear expired tokens
- Generate authentication header
- Returns the model form class
- Returns the form class for the application model
- Create an OAuth authorization response
- Overrides the dispatch method
- Verifies the request
- Validate the request
- Returns an error response
- Validate credentials
- Check if the token matches the given request
- Signs an ID token
- Return the keyword arguments for the server
- Validates the response type
- Revoke this access token
- Validate a request
- Authenticate the client
- Handles GET requests
django-oauth-toolkit Key Features
django-oauth-toolkit Examples and Code Snippets
{
"id": 1,
"type": "o_auth2_application",
"url": "/api/v2/applications/1/",
"related": {
"user": "/api/v2/users/1/",
"tokens": "/api/v2/applications/1/tokens/",
"activity_stream": "/api/v2/applications/1/activi
{
"name": "AuthCodeApp",
"user": 1,
"client_type": "confidential",
"redirect_uris": "http:///api/v2",
"authorization_grant_type": "authorization-code",
"skip_authorization": false
}
{
"id": 6,
"type": "application",
pip install django-oauth-toolkit
INSTALLED_APPS = [
...
'oauth2_provider',
]
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
]
}
version: "3.4"
x-service-volumes: &service-volumes
- ./:/usr/proj/:rw,cached
services:
ShopDjangoBN_Nginx:
image: ${DJ_NGINX_IMAGE}
ports:
- 8001:8001
volumes: *service-volumes
environment:
- NGINX_SHO
def get_token_response(token_value=None):
try:
token = get_access_token_model().objects.select_related(
"user", "application"
).get(token=token_value)
except ObjectDoesNotExist:
run_before = [
('oauth2_provider', '0001_initial'),
]
request.META['HTTP_AUTHORIZATION'] = "Bearer 123456"
class MyView(APIView):
authentication_classes = [OAuth2Authentication]
permission_classes = [TokenHasReadWriteScope]
self.initial(request, *args, **kwargs)
# part of initial:
# self.check_permissions(request)
# Get the appropriate handler method
if request.method.lower() in self.http_method_names:
handler = getattr(self, request.method.lower(),
def authenticate_header(self, request):
request.oauth2_error = {}
return super().authenticate_header(request)
Community Discussions
Trending Discussions on django-oauth-toolkit
QUESTION
I am trying to define different scopes for each oauth application in Django-oauth-toolkit. I realized I can define different scopes on the settings file. But it seems that they apply to every new oauth-application I create.
...ANSWER
Answered 2021-Aug-24 at 14:20When the scopes need to differ they must be included in the request to get an access token as specified here.
So basically the request to get an access token should look like:
QUESTION
I have developed a blog like project on the django rest framework and oauth2. I am now trying to separate the resource and authentication servers as shown here: https://django-oauth-toolkit.readthedocs.io/en/latest/resource_server.html
I have taken the following steps:
- set up the auth server as described in the docs
- added the below to settings.py in the auth server
ANSWER
Answered 2021-Apr-29 at 06:38I had the same problem when using the 'RESOURCE_SERVER_AUTH_TOKEN'
. So instead I used the client_id
and client_secret
.
Go ahead and try the following:
QUESTION
I want to add data (such as the token expiration date or user info) to the payload of the JWT generated by this library.
The current decoded payload of a JWT generated by this library is the following:
...ANSWER
Answered 2021-Apr-14 at 23:02drf-social-oauth2
doesn't provide a mechanism to easily override this setting, it overrides oauth2_provider.settings.ACCESS_TOKEN_GENERATOR
with their generate_token
method (https://github.com/wagnerdelima/drf-social-oauth2/blob/master/drf_social_oauth2/settings.py#L11-L14), this method doesn't include extra values, only the token.
You can do the same on your side overriding the value with a custom method that adds the needed keys.
QUESTION
Good morning or afternoon even good evening!
I have been trying to achieve the separating resource server from the auth server using OAuth Toolkit with Django and I got stuck.
Tryed:First, I have already tried the following:
Follow the tutorial with this tutorial and it works when it comes to serving projects with python manage.py runserver.
The whole structure is that I use Postmen as client and request to resource server and check the authenticated user with auth server so there is introspection process between resource and auth server.
As I mentioned, the whole idea works only when I serve project with python manage.py runserver. When deployed projects in Docker-Compose using Nginx and Gunicorn to serve projects, headache has come.
This was the final error - Max retries exceeded with url: /o/introspect/
When I tracked back to the root - Introspection: Failed POST to localhost:8000/o/introspect/ in token lookup
This is error in the client app - "Authentication credentials were not provided."
I found this issue is happened when the access token is expired or revoked and the system try to get a new access token to resource server from auth server.
Somehow, the introspection process is failed by for me an unknown reason!
Anybody hit this wall before?
Edit: (Thu Mar 4, 2021)I found another reason that can more related to the exact issue!
As the docker compose create services that each service serves one container consisting of image of the project(Django). Therefore, each project is isolated from each other!
This results in A project can be harder to request to B project as the port for B project cannot be reach in the A project.
A potential solution may be using the Nginx server proxy name (which is gonna be the same as the name of each service in docker compose) to make a request.
I am still trying to handle this! If anyone can help that would be really appreciate!
Edit: (Thu Mar 4, 2021 5:07PM Taiwan) Problem SovledSolution is demoed!
...ANSWER
Answered 2021-Mar-05 at 02:19So first, let me demo you the docker compose structure:
QUESTION
Why I have a problem with updating Django from version 1.11.29 to 2.0.13. When updating the library django-oauth-toolkit
to version 1.2.0 - version support Django 2.0, I receive this error:
ANSWER
Answered 2021-Mar-04 at 07:32Need update request library to version 2.23.0. And install idna==2.10
QUESTION
Why I have a problem with updating Django from version 1.11.29 to 2.0.13. When updating the library django-oauth-toolkit to version 1.2.0 - version support Django 2.0 I receive an error: __version__ = pkg_resources.require("django-oauth-toolkit")[0].version pkg_resources.ContextualVersionConflict: (urllib3 1.25.11 (/.virtualenvs/django-oauth-tookit-conflict/lib/python3.6/site-packages), Requirement.parse('urllib3<1.25,>=1.21.1'), {'requests'})
ANSWER
Answered 2021-Mar-04 at 07:26It's because was changed in /oauth2_provider/init.py
version = '0.11.0'
author = "Massimiliano Pippi & Federico Frenguelli"
default_app_config = 'oauth2_provider.apps.DOTConfig'
VERSION = version # synonym
To:
import pkg_resources
version = pkg_resources.require("django-oauth-toolkit")[0].version
default_app_config = "oauth2_provider.apps.DOTConfig"
QUESTION
Current Scenario:
I'm using Introspect to validate access token on the authentication server. This call returns only 'username' of the user from the authentication server and saves it in the resource server. The Id of the same user on the authentication server and the resource server are no necessarily the same.
Desired Scenario:
I want to receive more data about the user (email, phone number, address, etc..) and save it in the resource server.
What I have done so far:
I modified the django-oauth-toolkit/oauth2_provider/views/introspect.py/ get_token_response
to return the data I need.
What is remaining:
How do I save those data in the resource server? or is it better to make an api call to the authentication server whenever I require the user data?
...ANSWER
Answered 2021-Mar-01 at 13:12I achieved this by modifying get_token_response in IntrospectTokenView in the Auth-Server
QUESTION
I'm going to restrict my working rest_framework.views.APIView
inherited class, to be visible only by authenticated users.
I made these modifications:
- Added
authentication_classes
andpermission_classes
to my class:
ANSWER
Answered 2021-Jan-09 at 20:01Try djoser for authentication in Django rest framework
QUESTION
I run the following line of code on a Docker container:
...ANSWER
Answered 2020-Dec-01 at 13:40Your problem is here:
QUESTION
I have an django application with version 2.2.13 and django oauth toolkit 1.0.0. In the effort to update to Django 3.0, I need to update the django-oauth-toolkit, but every version after version 1.0.0, I run into a migration problem because my application (oauth2) extends the abstract application (AbstractApplication) model from the oauth2_provider (from django-oauth-toolkit).
...ANSWER
Answered 2020-Aug-24 at 19:59when you swap the application model, you should create and run the migration defining the swapped application model prior to setting OAUTH2_PROVIDER_APPLICATION_MODEL.
It is possible to force your migration providing the custom model to run in the right order by adding:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install django-oauth-toolkit
You can use django-oauth-toolkit like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page