Skip to content

Commit ff2d115

Browse files
stanleykcclaude
andcommitted
Fix token-info display and improve update-profile error handling
- Fix token-info table output to correctly extract email from JWT token fields (username/sub) instead of showing N/A - Add user's full name to token-info display when available - Improve update-profile error message for user ID mismatch to clearly explain the self-service limitation - Update user-guide.md documentation to match actual CLI behavior and document the update-profile limitation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Kevin Stanley <stanleyk@objectcomputing.com>
1 parent b2b7aec commit ff2d115

3 files changed

Lines changed: 64 additions & 10 deletions

File tree

unityauth-cli/docs/user-guide.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,10 @@ unityauth token-info
227227
| Field | Description |
228228
|-------|-------------|
229229
| Email | Authenticated user's email |
230-
| API URL | Current API endpoint |
231-
| Token Status | Valid/Expired/Not Found |
232-
| Expires | Token expiration time (if available) |
230+
| Name | User's full name (if available) |
231+
| API Endpoint | Current API endpoint |
232+
| Authenticated | Yes (shown when authenticated) |
233+
| Token Expires | Token expiration time (Unix timestamp) |
233234

234235
**Examples:**
235236

@@ -241,6 +242,24 @@ unityauth token-info
241242
unityauth token-info -o json
242243
```
243244

245+
**Sample Output:**
246+
247+
```
248+
+---------------+-------------------------+
249+
| Field | Value |
250+
+===============+=========================+
251+
| Email | admin@example.com |
252+
+---------------+-------------------------+
253+
| Name | Admin User |
254+
+---------------+-------------------------+
255+
| API Endpoint | https://auth.example.com|
256+
+---------------+-------------------------+
257+
| Authenticated | Yes |
258+
+---------------+-------------------------+
259+
| Token Expires | 1767196697 |
260+
+---------------+-------------------------+
261+
```
262+
244263
---
245264

246265
## Configuration Commands
@@ -494,10 +513,14 @@ unityauth user update-profile USER_ID [OPTIONS]
494513
**Behavior:**
495514

496515
- This is a **self-service** command: you can only update your own profile
497-
- The `USER_ID` must match your authenticated user ID
516+
- The `USER_ID` must match your authenticated user ID exactly
498517
- At least one option must be provided
499518
- Only the specified fields are updated; others remain unchanged
500519

520+
**Important Limitation:**
521+
522+
This command cannot be used by administrators to update other users' profiles. The backend enforces that the authenticated user can only modify their own account. To update another user's name or password, use the web interface or API directly.
523+
501524
**Examples:**
502525

503526
```bash
@@ -524,7 +547,7 @@ unityauth user update-profile 5 --dry-run --first-name John --last-name Smith
524547

525548
| Error | Cause | Solution |
526549
|-------|-------|----------|
527-
| "Permission denied" | User ID doesn't match authenticated user | Use `token-info` to find your user ID |
550+
| "User ID mismatch" | The user ID doesn't match your authenticated user | Use `token-info` to find your correct user ID. You can only update your own profile. |
528551
| "At least one field must be provided" | No options specified | Provide `--first-name`, `--last-name`, or `--password` |
529552
| "Password must be at least 8 characters" | Password too short | Use a longer password |
530553

unityauth-cli/src/unityauth_cli/commands/login.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,30 @@ def token_info(ctx: CLIContext, client: UnityAuthAPIClient) -> None:
167167
if ctx.output_format == 'json':
168168
console.print(format_json(response))
169169
else:
170-
# Extract key fields for table display
170+
# Extract email from various possible fields
171+
email = (
172+
response.get('username') or
173+
response.get('sub') or
174+
response.get('email') or
175+
response.get('userEmail', 'N/A')
176+
)
177+
178+
# Extract name if available
179+
first_name = response.get('first_name', '')
180+
last_name = response.get('last_name', '')
181+
full_name = f"{first_name} {last_name}".strip() if first_name or last_name else None
182+
183+
# Build display data
171184
display_data = {
172-
'User Email': response.get('email') or response.get('userEmail', 'N/A'),
173-
'User ID': response.get('userId') or response.get('id', 'N/A'),
174-
'API Endpoint': ctx.api_url,
175-
'Authenticated': 'Yes',
185+
'Email': email,
176186
}
177187

188+
if full_name:
189+
display_data['Name'] = full_name
190+
191+
display_data['API Endpoint'] = ctx.api_url
192+
display_data['Authenticated'] = 'Yes'
193+
178194
# Add expiration if present
179195
if 'exp' in response or 'expiration' in response:
180196
exp = response.get('exp') or response.get('expiration')

unityauth-cli/src/unityauth_cli/commands/users.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,21 @@ def update_profile(
342342
"Use 'unityauth token-info' to see your user details."
343343
)
344344
sys.exit(3)
345+
except ValidationError as e:
346+
error_msg = str(e).lower()
347+
# Check for user ID mismatch error from backend
348+
if "mismatch" in error_msg or "bad request" in error_msg:
349+
error(
350+
"User ID mismatch: You can only update your own profile",
351+
f"The user ID {user_id} does not match your authenticated user.\n\n"
352+
"To find your user ID:\n"
353+
" $ unityauth token-info\n\n"
354+
"Note: 'update-profile' is a self-service command. To update another\n"
355+
"user's details, an administrator must use the web interface or API directly."
356+
)
357+
else:
358+
error(str(e))
359+
sys.exit(1)
345360
except Exception as e:
346361
handle_error(e)
347362

0 commit comments

Comments
 (0)