VssConnection not working getting : {"VS30063: You are not authorized to access https://dev.azure.com."} error using .Net 6.0

Arshia Shaikh 22 Reputation points
2022-02-04T15:53:04.887+00:00

VssCredentials creds = new VssAadCredential(new VssAadToken("Bearer", accessToken)); // tried using this as well
//VssCredentials creds = new VssBasicCredential(string.Empty, accessToken); // tried using this as well
VssConnection connection = new VssConnection(new Uri("https://dev.azure.com/{organization}"), creds);
WorkItemTrackingHttpClient witClient = connection.GetClient<WorkItemTrackingHttpClient>();
Wiql query = new Wiql() { Query = "SELECT [Id], [Title], [State] FROM workitems WHERE [Work Item Type] = 'Bug' AND [Assigned To] = @Me" };
WorkItemQueryResult queryResults = witClient.QueryByWiqlAsync(query).Result;

When I am trying to execute the above code I am getting this error:
{"VS30063: You are not authorized to access https://dev.azure.com."}

When I am using .Net 6.0 I am getting this error but it is working for .Net 4.6.1

Microsoft Authenticator
Microsoft Authenticator
A Microsoft app for iOS and Android devices that enables authentication with two-factor verification, phone sign-in, and code generation.
6,149 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,446 questions
0 comments No comments
{count} votes