Skip to content

Commit 77e83c4

Browse files
committed
Don't throw in ClientContext.IsAppOnly() if AccessToken extraction is successful
1 parent a5162c7 commit 77e83c4

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/lib/PnP.Framework/Extensions/ClientContextExtensions.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,6 @@ public static ClientContext GetSiteCollectionContext(this ClientRuntimeContext c
576576
/// <returns>True if app-only, false otherwise</returns>
577577
public static bool IsAppOnly(this ClientRuntimeContext clientContext)
578578
{
579-
580579
// Set initial result to false
581580
var result = false;
582581

@@ -690,7 +689,18 @@ public static string GetAccessToken(this ClientRuntimeContext clientContext)
690689
};
691690
// Issue a dummy request to get it from the Authorization header
692691
clientContext.ExecutingWebRequest += handler;
693-
clientContext.ExecuteQuery();
692+
try
693+
{
694+
clientContext.ExecuteQuery();
695+
}
696+
catch (Exception ex)
697+
{
698+
// This can fail for whatever reason, but if we already have the AccessToken, it doesn't matter
699+
if (String.IsNullOrEmpty(accessToken))
700+
{
701+
throw new AggregateException("Fetching the AccessToken to inspect whether the ClientContext is AppOnly or not failed. There might be more information in the InnerExceptions.", ex);
702+
}
703+
}
694704
clientContext.ExecutingWebRequest -= handler;
695705
}
696706
}

0 commit comments

Comments
 (0)