Skip to content

Commit

Permalink
Move JWT token claims to v3_users_current (#4939)
Browse files Browse the repository at this point in the history
move token claims to v3_users_current, expand that response to cover most user needs in the angular client
  • Loading branch information
crutan authored Jan 29, 2025
1 parent 9610c95 commit 12e60e2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 1 addition & 3 deletions seed/landing/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ def get_token(cls, user):
token = super().get_token(user)

# Add custom claims
token["name"] = f"{user.first_name} {user.last_name}".strip()
token["username"] = user.username
token["email"] = user.email
# token["name"] = f"{user.first_name} {user.last_name}".strip()

return token
19 changes: 18 additions & 1 deletion seed/views/v3/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from seed.utils.api_schema import AutoSchemaHelper, swagger_auto_schema_org_query_param
from seed.utils.organizations import create_organization
from seed.utils.users import get_role_from_js
from seed.views.main import _get_default_org as get_default_org_for_user

_log = logging.getLogger(__name__)

Expand Down Expand Up @@ -258,7 +259,23 @@ def current(self, request):
required: true
type: string
"""
return JsonResponse({"pk": request.user.id})
response = dict(
list(
zip(
("org_id", "org_name", "org_role", "ali_name", "ali_id", "is_ali_root", "is_ali_leaf"),
get_default_org_for_user(request.user),
)
)
)
response["pk"] = request.user.id
response["id"] = request.user.id
response["first_name"] = request.user.first_name
response["last_name"] = request.user.last_name
response["email"] = request.user.email
response["username"] = request.user.username
response["is_superuser"] = request.user.is_superuser
response["api_key"] = request.user.api_key
return JsonResponse(response)

@swagger_auto_schema(
manual_parameters=[AutoSchemaHelper.query_org_id_field()],
Expand Down

0 comments on commit 12e60e2

Please sign in to comment.