Any examples using a managed identity for authentication?

Open
#34 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Documentation
Clarity
Needs clarification
Activity status
Stale
Tech stack
azure, csharp, playwright

Research direction

Start from the C# managed-identity token acquisition snippet in the issue and verify the reported 401 against the Azure Playwright Testing service and the 2025-09-01 API version. Done means a repository guide or sample explains the required managed-identity setup, token scope, and working connection flow.

Written by the indexing model from the issue text.

Description

enhancement

Attempt to use a managed identity but getting a 401, was hoping there was a guide or sample that could do this.

Have it working using a standard token (although took a long time to realise my api version was using the old 2023 preview format instead of the 2025-09-01 one).

here's my rough method of trying to get the token, i'm assuming this either doesn't work at all or I'm guessing it for the wrong subject or similar.

	TokenCredential credential;
			if (string.IsNullOrEmpty(managedIdentityClientId))
			{
				throw new Exception("Managed identity client ID is not configured.");
			}

			_logger.LogInformation("Using user-assigned managed identity with client ID: {ClientId}", managedIdentityClientId);
			credential = new DefaultAzureCredential(new DefaultAzureCredentialOptions
			{
				ManagedIdentityClientId = managedIdentityClientId
			});
			
			// Get access token for Azure Playwright Testing service
			// The scope for Azure Playwright Testing is: https://playwright.microsoft.com/.default
			var tokenRequestContext = new TokenRequestContext(new[] { "https://playwright.microsoft.com/.default" });
			var accessToken = await credential.GetTokenAsync(tokenRequestContext, CancellationToken.None);
		
		var wsEndpoint = $"{serviceUrl}?runId={Uri.EscapeDataString(runId)}&os={os}&api-version={apiVersion}";
		_logger.LogInformation($"Access token: {accessToken.Token}");
		
		var options = new BrowserTypeConnectOptions
		{
			Timeout = 3 * 60 * 1000, // 3 minutes
			Headers = new Dictionary<string, string>
			{
				{ "Authorization", $"Bearer {accessToken.Token}" }
			},
			ExposeNetwork = "<loopback>", // Use loopback to expose network
		};
Dominant language
No language data
Stars
14
Forks
18
Avg merge
1h 18m
Merged PRs (30d)
2

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Azure/playwright-workspaces

All issues in Azure/playwright-workspaces

Similar issues

More Security issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.