Skip to content

Commit c8eee2c

Browse files
vector-kerrn2ygk
andauthored
Update createapplication command (#1132)
* Add --algorithm argument and fix --skip-authorization help text for createapplication command * Add unit test for update to createapplication command * Add to AUTHORS * Update changelog for createapplication command changes * Add documentation for 'createapplication' command to 'management_commands.rst' Co-authored-by: Alan Crosswell <[email protected]>
1 parent a62195b commit c8eee2c

File tree

5 files changed

+63
-1
lines changed

5 files changed

+63
-1
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Bart Merenda
2323
Bas van Oostveen
2424
Brian Helba
2525
Carl Schwan
26+
Daniel 'Vector' Kerr
2627
Dave Burkholder
2728
David Fischer
2829
David Smith

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
If you've [customized OIDC responses](https://django-oauth-toolkit.readthedocs.io/en/latest/oidc.html#customizing-the-oidc-responses)
3333
and want to retain the pre-2.x behavior, set `oidc_claim_scope = None` in your subclass of `OAuth2Validator`.
3434
* #1108 OIDC: Make the `access_token` available to `get_oidc_claims` when called from `get_userinfo_claims`.
35+
* #1132: Added `--algorithm` argument to `createapplication` management command
3536

3637
### Fixed
3738
* #1108 OIDC: Fix `validate_bearer_token()` to properly set `request.scopes` to the list of granted scopes.
39+
* #1132: Fixed help text for `--skip-authorization` argument of the `createapplication` management command
3840

3941
### Removed
4042
* #1124 (**Breaking**, **Security**) Removes support for insecure `urn:ietf:wg:oauth:2.0:oob` and `urn:ietf:wg:oauth:2.0:oob:auto` which are replaced

docs/management_commands.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Management commands
44
Django OAuth Toolkit exposes some useful management commands that can be run via shell or by other means (eg: cron)
55

66
.. _cleartokens:
7+
.. _createapplication:
8+
79

810
cleartokens
911
~~~~~~~~~~~
@@ -21,3 +23,38 @@ To prevent the CPU and RAM high peaks during deletion process use ``CLEAR_EXPIRE
2123

2224
Note: Refresh tokens need to expire before AccessTokens can be removed from the
2325
database. Using ``cleartokens`` without ``REFRESH_TOKEN_EXPIRE_SECONDS`` has limited effect.
26+
27+
28+
29+
createapplication
30+
~~~~~~~~~~~~~~~~~
31+
32+
The ``createapplication`` management command provides a shortcut to create a new application in a programmatic way.
33+
34+
.. code-block:: sh
35+
36+
usage: manage.py createapplication [-h] [--client-id CLIENT_ID] [--user USER] [--redirect-uris REDIRECT_URIS]
37+
[--client-secret CLIENT_SECRET] [--name NAME] [--skip-authorization] [--version] [-v {0,1,2,3}]
38+
[--settings SETTINGS] [--pythonpath PYTHONPATH] [--traceback] [--no-color] [--force-color]
39+
[--skip-checks]
40+
client_type authorization_grant_type
41+
42+
Shortcut to create a new application in a programmatic way
43+
44+
positional arguments:
45+
client_type The client type, can be confidential or public
46+
authorization_grant_type
47+
The type of authorization grant to be used
48+
49+
optional arguments:
50+
-h, --help show this help message and exit
51+
--client-id CLIENT_ID
52+
The ID of the new application
53+
--user USER The user the application belongs to
54+
--redirect-uris REDIRECT_URIS
55+
The redirect URIs, this must be a space separated string e.g 'URI1 URI2'
56+
--client-secret CLIENT_SECRET
57+
The secret for this application
58+
--name NAME The name this application
59+
--skip-authorization The ID of the new application
60+
...

oauth2_provider/management/commands/createapplication.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ def add_arguments(self, parser):
4949
parser.add_argument(
5050
"--skip-authorization",
5151
action="store_true",
52-
help="The ID of the new application",
52+
help="If set, completely bypass the authorization form, even on the first use of the application",
53+
)
54+
parser.add_argument(
55+
"--algorithm",
56+
type=str,
57+
help="The OIDC token signing algorithm for this application (e.g., 'RS256' or 'HS256')",
5358
)
5459

5560
def handle(self, *args, **options):

tests/test_commands.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from io import StringIO
22

3+
import pytest
34
from django.contrib.auth import get_user_model
45
from django.contrib.auth.hashers import check_password
56
from django.core.management import call_command
@@ -8,6 +9,8 @@
89

910
from oauth2_provider.models import get_application_model
1011

12+
from . import presets
13+
1114

1215
Application = get_application_model()
1316

@@ -112,6 +115,20 @@ def test_application_created_with_user(self):
112115

113116
self.assertEqual(app.user, user)
114117

118+
@pytest.mark.usefixtures("oauth2_settings")
119+
@pytest.mark.oauth2_settings(presets.OIDC_SETTINGS_RW)
120+
def test_application_created_with_algorithm(self):
121+
call_command(
122+
"createapplication",
123+
"confidential",
124+
"authorization-code",
125+
"--redirect-uris=http://example.com http://example2.com",
126+
"--algorithm=RS256",
127+
)
128+
app = Application.objects.get()
129+
130+
self.assertEqual(app.algorithm, "RS256")
131+
115132
def test_validation_failed_message(self):
116133
output = StringIO()
117134
call_command(

0 commit comments

Comments
 (0)