Skip to content

Commit 5586563

Browse files
CopilotJesuTerraz
andauthored
Address code review feedback for resource token acquisition (#226)
* Initial plan * Address code review feedback: logging, validation, and documentation fixes Co-authored-by: JesuTerraz <96103167+JesuTerraz@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: JesuTerraz <96103167+JesuTerraz@users.noreply.github.com>
1 parent 06618a8 commit 5586563

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

docs/commands/develop/develop-gettoken.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ a365 develop get-token [options]
2424
| `--verbose` | `-v` | Show detailed output including full token | `false` |
2525
| `--force-refresh` | | Force token refresh bypassing cache | `false` |
2626
| `--resource` | | Resource keyword to get token for (mcp, powerplatform) | `mcp` |
27-
| `--resource-id` | | Resource application ID (GUID) for custom resources | Agent 365 Tools App ID |
27+
| `--resource-id` | | Resource application ID (GUID) for custom resources | None |
2828

2929
### Resource Options
3030

@@ -119,7 +119,7 @@ curl -H "Authorization: Bearer $TOKEN" https://agent365.svc.cloud.microsoft/agen
119119

120120
### Get token for Power Platform API
121121
```bash
122-
a365 develop get-token --resource powerplatform --scopes https://api.powerplatform.com/.default
122+
a365 develop get-token --resource powerplatform --scopes .default
123123
```
124124

125125
### Get token for a custom resource

src/Microsoft.Agents.A365.DevTools.Cli/Commands/DevelopSubcommands/GetTokenSubcommand.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ public static Command CreateCommand(
147147
string resourceDisplayName;
148148
if (!string.IsNullOrWhiteSpace(resourceId))
149149
{
150+
// Validate that resource ID is a valid GUID
151+
if (!Guid.TryParse(resourceId, out _))
152+
{
153+
logger.LogError("Invalid resource application ID: {ResourceId}. Expected a valid GUID.", resourceId);
154+
logger.LogInformation("");
155+
logger.LogInformation("Example: a365 develop get-token --resource-id 12345678-1234-1234-1234-123456789abc --scopes .default");
156+
Environment.Exit(1);
157+
return;
158+
}
159+
150160
// User provided explicit resource ID
151161
resourceAppId = resourceId;
152162
resourceDisplayName = $"Custom Resource ({resourceId})";
@@ -184,7 +194,7 @@ public static Command CreateCommand(
184194
logger.LogInformation("Manifest-based scopes are only supported for the default flow.");
185195
logger.LogInformation("Please omit the --resource and --resource-id options if you'd like to use manifest-based scopes.");
186196
logger.LogInformation("");
187-
logger.LogInformation("Example: a365 develop get-token --resource powerplatform --scopes https://api.powerplatform.com/.default");
197+
logger.LogInformation("Example: a365 develop get-token --resource powerplatform --scopes .default");
188198
Environment.Exit(1);
189199
return;
190200
}
@@ -225,7 +235,7 @@ public static Command CreateCommand(
225235
}
226236

227237
logger.LogInformation("");
228-
logger.LogInformation("Agent 365 Tools Resource App ID: {AppId}", resourceAppId);
238+
logger.LogInformation("Resource App ID: {AppId}", resourceAppId);
229239
logger.LogInformation("Requesting scopes: {Scopes}", string.Join(", ", requestedScopes));
230240
logger.LogInformation("");
231241

@@ -361,7 +371,7 @@ private static async Task AcquireAndDisplayTokenAsync(
361371
}
362372
catch (Exception ex)
363373
{
364-
logger.LogError("Failed to acquire token: {Message}", ex.Message);
374+
logger.LogError(ex, "Failed to acquire token: {Message}", ex.Message);
365375
Environment.Exit(1);
366376
}
367377
}

0 commit comments

Comments
 (0)