Skip to content

Commit

Permalink
Do not error when missing some JWT item
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCoding committed Nov 26, 2024
1 parent 20f43da commit 8caa6a8
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ansible_base/jwt_consumer/common/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ def parse_jwt_token(self, request):

if not self.user:
# Either the user wasn't cached or the requested user was not in the DB so we need to make a new one
resource_kwargs = {}
for resource_key, token_key in (('resource_data', 'user_data'), ('ansible_id', 'sub'), ('service_id', 'service_id')):
if token_key not in self.token:
logger.warning(f'Missing {token_key} in JWT data, omitting {resource_key} from local resource entry')
resource_kwargs[resource_key] = self.token[token_key]
try:
resource = Resource.create_resource(
ResourceType.objects.get(name="shared.user"),
resource_data=self.token["user_data"],
ansible_id=self.token["sub"],
service_id=self.token["service_id"],
)
resource = Resource.create_resource(ResourceType.objects.get(name="shared.user"), **resource_kwargs)
self.user = resource.content_object
logger.info(f"New user {self.user.username} created from JWT auth")
except IntegrityError as exc:
Expand Down

0 comments on commit 8caa6a8

Please sign in to comment.