Skip to content
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

Apply service_id for user if creating from JWT data #612

Draft
wants to merge 2 commits into
base: devel
Choose a base branch
from
Draft
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
5 changes: 4 additions & 1 deletion ansible_base/jwt_consumer/common/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ def parse_jwt_token(self, request):
# Either the user wasn't cached or the requested user was not in the DB so we need to make a new one
try:
resource = Resource.create_resource(
ResourceType.objects.get(name="shared.user"), resource_data=self.token["user_data"], ansible_id=self.token["sub"]
ResourceType.objects.get(name="shared.user"),
resource_data=self.token["user_data"],
ansible_id=self.token["sub"],
service_id=self.token["service_id"],
)
self.user = resource.content_object
logger.info(f"New user {self.user.username} created from JWT auth")
Expand Down
2 changes: 2 additions & 0 deletions test_app/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from ansible_base.oauth2_provider.fixtures import * # noqa: F403, F401
from ansible_base.rbac import permission_registry
from ansible_base.rbac.models import RoleDefinition
from ansible_base.resource_registry.models.service_identifier import service_id
from test_app import models


Expand Down Expand Up @@ -517,6 +518,7 @@ def __init__(self):
"exp": int(expiration_date.timestamp()),
"aud": "ansible-services",
"sub": "1e3de989-5286-48a6-83d4-5de9a6618ffd",
"service_id": service_id(),
"user_data": {
"username": "john.westcott.iv",
"first_name": "john",
Expand Down
Loading