What is the version of your SharePoint? SharePoint Online or SharePoint Server Subscription Edition?
If you are using SharePoint Online, as this authentication method is only supported in SharePoint Server Subscription Edition, it is not possible.
If you are using SharePoint Server Subscription Edition, first you need to obtain the claims from the OIDC token after authenticating the user, then create the ClientContext in the SharePoint Server Subscription Edition.
Here is a simplified example of how you might set this up in code:
ClientContext clientContext = new ClientContext(<sharepointurl>);
clientContext.AuthenticationMode = ClientAuthenticationMode.Anonymous;
clientContext.ExecutingWebRequest += (sender, e) =>
{
e.WebRequestExecutor.RequestHeaders["Authorization"] = "Bearer " + accessToken; // Use your access token
};
Reference:
https://learn.microsoft.com/en-us/sharepoint/security-for-sharepoint-server/oidc-1-0-authentication
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.