Skip to content

Commit f98abe3

Browse files
tolgakiclaude
andauthored
Fix missing Graph permissions, stale token fallback, and wire logger (#10)
- Rust setup scripts: add all 7 required Graph permissions (was only User.Read) and update admin consent scope string to match - Swift AuthService.refreshToken(): clear accessToken on silent refresh failure instead of returning the stale expired token - Swift setup scripts: generate full Configuration.plist with RedirectUri, TenantId, Scopes, and Endpoint (was only ClientId) - .NET WireLog: re-create StringContent after reading body for logging so base.SendAsync() doesn't send an empty payload at verbosity 2 Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8464640 commit f98abe3

6 files changed

Lines changed: 62 additions & 5 deletions

File tree

dotnet/a2a/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
449449
foreach (var h in body.Headers) Console.WriteLine($" {h.Key}: {string.Join(", ", h.Value)}");
450450
var text = await body.ReadAsStringAsync(ct);
451451
Console.WriteLine($" Body: {Trunc(text, 500)}");
452+
// Re-create content so the stream can be read again by SendAsync
453+
var newContent = new StringContent(text, System.Text.Encoding.UTF8, body.Headers.ContentType?.MediaType ?? "application/json");
454+
req.Content = newContent;
452455
}
453456

454457
Console.ResetColor();

rust/a2a/setup-app-registration.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ $GraphApi = "00000003-0000-0000-c000-000000000000"
1313

1414
# Microsoft Graph delegated permission GUIDs
1515
$Permissions = @{
16-
"User.Read" = "e1fe6dd8-ba31-4d61-89e7-88639da4683d"
16+
"User.Read" = "e1fe6dd8-ba31-4d61-89e7-88639da4683d"
17+
"Sites.Read.All" = "205e70e5-aba6-4c52-a976-6d2d46c48043"
18+
"Mail.Read" = "570282fd-fa5c-430d-a7fd-fc8dc98a9dca"
19+
"People.Read.All" = "b89f9189-71a5-4e70-b041-9887f0bc7e4a"
20+
"OnlineMeetingTranscript.Read.All" = "30b87d18-ebb1-45db-97f8-82ccb1f0190c"
21+
"Chat.Read" = "f501c180-9344-439a-bca0-6cbf209fd270"
22+
"ChannelMessage.Read.All" = "767156cb-16ae-4d10-8f8b-41b657c8c8c8"
23+
"ExternalItem.Read.All" = "922f9392-b1b7-483c-a4be-0089be7704fb"
1724
}
1825

1926
Write-Host "── Creating app registration: $DisplayName ──"
@@ -48,7 +55,7 @@ $AppSpId = az ad sp show --id $AppId --query id -o tsv
4855

4956
az rest --method POST `
5057
--uri "https://graph.microsoft.com/v1.0/oauth2PermissionGrants" `
51-
--body "{`"clientId`":`"$AppSpId`",`"consentType`":`"AllPrincipals`",`"resourceId`":`"$GraphSpId`",`"scope`":`"User.Read`"}" `
58+
--body "{`"clientId`":`"$AppSpId`",`"consentType`":`"AllPrincipals`",`"resourceId`":`"$GraphSpId`",`"scope`":`"User.Read Sites.Read.All Mail.Read People.Read.All OnlineMeetingTranscript.Read.All Chat.Read ChannelMessage.Read.All ExternalItem.Read.All`"}" `
5259
-o none
5360

5461
Write-Host ""

rust/a2a/setup-app-registration.sh

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ GRAPH_API="00000003-0000-0000-c000-000000000000"
1414

1515
# Microsoft Graph delegated permission GUIDs
1616
USER_READ="e1fe6dd8-ba31-4d61-89e7-88639da4683d"
17+
SITES_READ_ALL="205e70e5-aba6-4c52-a976-6d2d46c48043"
18+
MAIL_READ="570282fd-fa5c-430d-a7fd-fc8dc98a9dca"
19+
PEOPLE_READ_ALL="b89f9189-71a5-4e70-b041-9887f0bc7e4a"
20+
ONLINE_MEETING_TRANSCRIPT_READ_ALL="30b87d18-ebb1-45db-97f8-82ccb1f0190c"
21+
CHAT_READ="f501c180-9344-439a-bca0-6cbf209fd270"
22+
CHANNEL_MESSAGE_READ_ALL="767156cb-16ae-4d10-8f8b-41b657c8c8c8"
23+
EXTERNAL_ITEM_READ_ALL="922f9392-b1b7-483c-a4be-0089be7704fb"
1724

1825
echo "── Creating app registration: $DISPLAY_NAME ──"
1926

@@ -29,10 +36,24 @@ echo "── Adding Graph API delegated permissions ──"
2936

3037
az ad app permission add --id "$APP_ID" --api "$GRAPH_API" \
3138
--api-permissions \
32-
"${USER_READ}=Scope"
39+
"${USER_READ}=Scope" \
40+
"${SITES_READ_ALL}=Scope" \
41+
"${MAIL_READ}=Scope" \
42+
"${PEOPLE_READ_ALL}=Scope" \
43+
"${ONLINE_MEETING_TRANSCRIPT_READ_ALL}=Scope" \
44+
"${CHAT_READ}=Scope" \
45+
"${CHANNEL_MESSAGE_READ_ALL}=Scope" \
46+
"${EXTERNAL_ITEM_READ_ALL}=Scope"
3347

3448
echo " Permissions added:"
3549
echo " - User.Read"
50+
echo " - Sites.Read.All"
51+
echo " - Mail.Read"
52+
echo " - People.Read.All"
53+
echo " - OnlineMeetingTranscript.Read.All"
54+
echo " - Chat.Read"
55+
echo " - ChannelMessage.Read.All"
56+
echo " - ExternalItem.Read.All"
3657

3758
echo "── Creating service principal ──"
3859

@@ -49,7 +70,7 @@ az rest --method POST \
4970
\"clientId\": \"$APP_SP_ID\",
5071
\"consentType\": \"AllPrincipals\",
5172
\"resourceId\": \"$GRAPH_SP_ID\",
52-
\"scope\": \"User.Read\"
73+
\"scope\": \"User.Read Sites.Read.All Mail.Read People.Read.All OnlineMeetingTranscript.Read.All Chat.Read ChannelMessage.Read.All ExternalItem.Read.All\"
5374
}" -o none
5475

5576
echo ""

swift/a2a/A2A Chat/Services/AuthService.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,13 @@ class AuthService {
171171

172172
func refreshToken() async -> String? {
173173
guard application != nil else { return accessToken }
174-
_ = try? await acquireTokenSilently()
174+
do {
175+
_ = try await acquireTokenSilently()
176+
} catch {
177+
log.error("refreshToken — silent refresh failed: \(error.localizedDescription)")
178+
accessToken = nil
179+
isAuthenticated = false
180+
}
175181
return accessToken
176182
}
177183

swift/a2a/setup-app-registration.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ $PlistContent = @"
7171
<dict>
7272
<key>ClientId</key>
7373
<string>$AppId</string>
74+
<key>RedirectUri</key>
75+
<string>$RedirectUri</string>
76+
<key>TenantId</key>
77+
<string>common</string>
78+
<key>Scopes</key>
79+
<array>
80+
<string>https://graph.microsoft.com/.default</string>
81+
</array>
82+
<key>Endpoint</key>
83+
<string>YOUR_ENDPOINT_URL</string>
7484
</dict>
7585
</plist>
7686
"@

swift/a2a/setup-app-registration.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ cat > "$SCRIPT_DIR/A2A Chat/Configuration.plist" <<PLIST
8585
<dict>
8686
<key>ClientId</key>
8787
<string>$APP_ID</string>
88+
<key>RedirectUri</key>
89+
<string>$REDIRECT_URI</string>
90+
<key>TenantId</key>
91+
<string>common</string>
92+
<key>Scopes</key>
93+
<array>
94+
<string>https://graph.microsoft.com/.default</string>
95+
</array>
96+
<key>Endpoint</key>
97+
<string>YOUR_ENDPOINT_URL</string>
8898
</dict>
8999
</plist>
90100
PLIST

0 commit comments

Comments
 (0)