Azure / Azure/playwright-workspaces

Any examples using a managed identity for authentication?

Open
#34 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
No language data
Stars
14
Forks
18
Avg merge
1h 18m
Merged PRs (30d)
2

Description

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
{
{ "Authorization", $"Bearer {accessToken.Token}" }
},
ExposeNetwork = "", // Use loopback to expose network
};
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.