Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ repos:
hooks:
- id: flake8
exclude: ^(oauth2_provider/migrations/|tests/migrations/)
- repo: https://github.com/sphinx-contrib/sphinx-lint
rev: v0.3
hooks:
- id: sphinx-lint
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Jim Graham
Jonas Nygaard Pedersen
Jonathan Steffan
Jozef Knaperek
Julien Palard
Jun Zhou
Kristian Rune Larsen
Michael Howitz
Expand Down
2 changes: 1 addition & 1 deletion docs/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ Glossary

Refresh Token
A token the authorization server may issue to clients and can be swapped for a brand new access token, without
repeating the authorization process. It has no expire time.
repeating the authorization process. It has no expire time.
16 changes: 8 additions & 8 deletions docs/management_commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,27 @@ The ``createapplication`` management command provides a shortcut to create a new
.. code-block:: sh

usage: manage.py createapplication [-h] [--client-id CLIENT_ID] [--user USER] [--redirect-uris REDIRECT_URIS]
[--client-secret CLIENT_SECRET] [--name NAME] [--skip-authorization] [--version] [-v {0,1,2,3}]
[--settings SETTINGS] [--pythonpath PYTHONPATH] [--traceback] [--no-color] [--force-color]
[--skip-checks]
client_type authorization_grant_type
[--client-secret CLIENT_SECRET] [--name NAME] [--skip-authorization] [--version] [-v {0,1,2,3}]
[--settings SETTINGS] [--pythonpath PYTHONPATH] [--traceback] [--no-color] [--force-color]
[--skip-checks]
client_type authorization_grant_type

Shortcut to create a new application in a programmatic way

positional arguments:
client_type The client type, can be confidential or public
authorization_grant_type
The type of authorization grant to be used
The type of authorization grant to be used

optional arguments:
-h, --help show this help message and exit
--client-id CLIENT_ID
The ID of the new application
The ID of the new application
--user USER The user the application belongs to
--redirect-uris REDIRECT_URIS
The redirect URIs, this must be a space separated string e.g 'URI1 URI2'
The redirect URIs, this must be a space separated string e.g 'URI1 URI2'
--client-secret CLIENT_SECRET
The secret for this application
The secret for this application
--name NAME The name this application
--skip-authorization The ID of the new application
...
47 changes: 24 additions & 23 deletions docs/oidc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -249,38 +249,39 @@ our custom validator. It takes one of two forms:

The first form gets passed a request object, and should return a dictionary
mapping a claim name to claim data::

class CustomOAuth2Validator(OAuth2Validator):
# Set `oidc_claim_scope = None` to ignore scopes that limit which claims to return,
# otherwise the OIDC standard scopes are used.
# Set `oidc_claim_scope = None` to ignore scopes that limit which claims to return,
# otherwise the OIDC standard scopes are used.

def get_additional_claims(self, request):
return {
"given_name": request.user.first_name,
"family_name": request.user.last_name,
"name": ' '.join([request.user.first_name, request.user.last_name]),
"preferred_username": request.user.username,
"email": request.user.email,
}
return {
"given_name": request.user.first_name,
"family_name": request.user.last_name,
"name": ' '.join([request.user.first_name, request.user.last_name]),
"preferred_username": request.user.username,
"email": request.user.email,
}


The second form gets no request object, and should return a dictionary
mapping a claim name to a callable, accepting a request and producing
the claim data::
class CustomOAuth2Validator(OAuth2Validator):
# Extend the standard scopes to add a new "permissions" scope
# which returns a "permissions" claim:
oidc_claim_scope = OAuth2Validator.oidc_claim_scope
oidc_claim_scope.update({"permissions": "permissions"})

def get_additional_claims(self):
return {
"given_name": lambda request: request.user.first_name,
"family_name": lambda request: request.user.last_name,
"name": lambda request: ' '.join([request.user.first_name, request.user.last_name]),
"preferred_username": lambda request: request.user.username,
"email": lambda request: request.user.email,
"permissions": lambda request: list(request.user.get_group_permissions()),
}
# Extend the standard scopes to add a new "permissions" scope
# which returns a "permissions" claim:
oidc_claim_scope = OAuth2Validator.oidc_claim_scope
oidc_claim_scope.update({"permissions": "permissions"})

def get_additional_claims(self):
return {
"given_name": lambda request: request.user.first_name,
"family_name": lambda request: request.user.last_name,
"name": lambda request: ' '.join([request.user.first_name, request.user.last_name]),
"preferred_username": lambda request: request.user.username,
"email": lambda request: request.user.email,
"permissions": lambda request: list(request.user.get_group_permissions()),
}


Standard claim ``sub`` is included by default, to remove it override ``get_claim_dict``.
Expand Down
2 changes: 1 addition & 1 deletion docs/rest-framework/permissions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ The following is a minimal OAS declaration that shows the same required alternat
to try it in the `swagger editor <https://editor.swagger.io>`_.

.. literalinclude:: openapi.yaml
:language: YAML
:language: YAML
2 changes: 1 addition & 1 deletion docs/templates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,4 @@ This template gets passed the following template context variable:

.. important::
To override successfully this template you should provide a form that posts to the same URL, example:
``<form method="post" action="">``
``<form method="post" action="">``
4 changes: 2 additions & 2 deletions docs/tutorial/tutorial_05.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ We'll add ours now in ``tutorial/tasks.py``:

@shared_task
def clear_tokens():
from oauth2_provider.models import clear_expired
from oauth2_provider.models import clear_expired

clear_expired()
clear_expired()

Finally, update ``tutorial/__init__.py`` to make sure Celery gets loaded when the app starts up:

Expand Down
2 changes: 1 addition & 1 deletion docs/views/mixins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Mixins for Class Based Views
============================

.. automodule:: oauth2_provider.views.mixins
:members:
:members:
9 changes: 8 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ envlist =
flake8,
migrations,
docs,
sphinxlint,
py{37,38,39}-dj22,
py{37,38,39,310}-dj32,
py{38,39,310}-dj40,
Expand All @@ -11,7 +12,7 @@ envlist =
[gh-actions]
python =
3.7: py37
3.8: py38, docs, flake8, migrations
3.8: py38, docs, flake8, migrations, sphinxlint
3.9: py39
3.10: py310

Expand Down Expand Up @@ -56,6 +57,12 @@ passenv =
ignore_errors = true
ignore_outcome = true

[testenv:sphinxlint]
deps = sphinx-lint
skip_install = True
commands =
sphinx-lint docs/

[testenv:{docs,livedocs}]
basepython = python3.8
changedir = docs
Expand Down