- Notifications
You must be signed in to change notification settings - Fork 825
HTTP Basic Auth support for introspection (Fix issue #709)#725
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
14 commits Select commit Hold shift + click to select a range
7aff8e3 fix issue #709
Abhishek8394 1181ed5 Merge branch 'master' into issue-709
auvipy 189796d fix failing tests after master merge
Abhishek8394 6d15b0b add newline
Abhishek8394 01f6393 merge from master
Abhishek8394 1ddb1de Merge branch 'master' into issue-709
auvipy a4ee961 Merge branch 'master' into issue-709
Abhishek8394 17c2ef5 Merge branch 'master' into issue-709
marianoeramirez 77d1e01 Merge branch 'master' into issue-709
MattBlack85 98874c8 Merge branch 'master' into issue-709
n2ygk 41352a7 Merge 'master' into issue-709
Abhishek8394 ff67402 update AUTHORS and CHANGELOG
Abhishek8394 a093565 fix flake8 failing tests
Abhishek8394 3db864d document RESOURCE_SERVER_INTROSPECTION_CREDENTIALS
n2ygk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -9,6 +9,8 @@ | ||
| from oauth2_provider.models import get_access_token_model, get_application_model | ||
| from oauth2_provider.settings import oauth2_settings | ||
| from .utils import get_basic_auth_header | ||
| Application = get_application_model() | ||
| AccessToken = get_access_token_model() | ||
| @@ -19,9 +21,12 @@ class TestTokenIntrospectionViews(TestCase): | ||
| """ | ||
| Tests for Authorized Token Introspection Views | ||
| """ | ||
| def setUp(self): | ||
| self.resource_server_user = UserModel.objects.create_user("resource_server", "[email protected]") | ||
| self.test_user = UserModel.objects.create_user("bar_user", "[email protected]") | ||
| self.resource_server_user = UserModel.objects.create_user( | ||
| "resource_server", "[email protected]") | ||
| self.test_user = UserModel.objects.create_user( | ||
| "bar_user", "[email protected]") | ||
| self.application = Application.objects.create( | ||
| name="Test Application", | ||
| @@ -256,3 +261,63 @@ def test_view_post_notexisting_token(self): | ||
| self.assertDictEqual(content,{ | ||
| "active": False, | ||
| }) | ||
| def test_view_post_valid_client_creds_basic_auth(self): | ||
| """Test HTTP basic auth working | ||
| """ | ||
| auth_headers = get_basic_auth_header( | ||
| self.application.client_id, self.application.client_secret) | ||
| response = self.client.post( | ||
| reverse("oauth2_provider:introspect"), | ||
| {"token": self.valid_token.token}, | ||
| **auth_headers) | ||
| self.assertEqual(response.status_code, 200) | ||
| content = response.json() | ||
| self.assertIsInstance(content, dict) | ||
| self.assertDictEqual(content,{ | ||
| "active": True, | ||
| "scope": self.valid_token.scope, | ||
| "client_id": self.valid_token.application.client_id, | ||
| "username": self.valid_token.user.get_username(), | ||
| "exp": int(calendar.timegm(self.valid_token.expires.timetuple())), | ||
| }) | ||
| def test_view_post_invalid_client_creds_basic_auth(self): | ||
| """Must fail for invalid client credentials | ||
| """ | ||
| auth_headers = get_basic_auth_header( | ||
| self.application.client_id, self.application.client_secret + "_so_wrong") | ||
| response = self.client.post( | ||
| reverse("oauth2_provider:introspect"), | ||
| {"token": self.valid_token.token}, | ||
| **auth_headers) | ||
| self.assertEqual(response.status_code, 403) | ||
| def test_view_post_valid_client_creds_plaintext(self): | ||
| """Test introspecting with credentials in request body | ||
| """ | ||
| response = self.client.post( | ||
| reverse("oauth2_provider:introspect"), | ||
| {"token": self.valid_token.token, | ||
| "client_id": self.application.client_id, | ||
| "client_secret": self.application.client_secret}) | ||
| self.assertEqual(response.status_code, 200) | ||
| content = response.json() | ||
| self.assertIsInstance(content, dict) | ||
| self.assertDictEqual(content,{ | ||
| "active": True, | ||
| "scope": self.valid_token.scope, | ||
| "client_id": self.valid_token.application.client_id, | ||
| "username": self.valid_token.user.get_username(), | ||
| "exp": int(calendar.timegm(self.valid_token.expires.timetuple())), | ||
| }) | ||
| def test_view_post_invalid_client_creds_plaintext(self): | ||
| """Must fail for invalid creds in request body. | ||
| """ | ||
| response = self.client.post( | ||
| reverse("oauth2_provider:introspect"), | ||
| {"token": self.valid_token.token, | ||
| "client_id": self.application.client_id, | ||
| "client_secret": self.application.client_secret + "_so_wrong"}) | ||
| self.assertEqual(response.status_code, 403) | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.