pyrit.auth.ManualCopilotAuthenticator#

class ManualCopilotAuthenticator(*, access_token: str | None = None)[source]#

Bases: Authenticator

Simple authenticator that uses a manually-provided access token for Microsoft Copilot.

This authenticator is useful for testing or environments where browser automation is not possible. Users can obtain the access token from browser DevTools and provide it directly.

How to obtain the access token:
  1. Open the Copilot webapp (e.g., https://m365.cloud.microsoft/chat) in a browser.

  2. Open DevTools (F12 or Ctrl+Shift+I).

  3. Go to the Network tab.

  4. Filter by “Socket” connections or search for “Chathub”.

  5. Start typing in the chat to initiate a WebSocket connection.

  6. Look for the latest WebSocket connection to substrate.office.com/m365Copilot/Chathub.

  7. You may find the access_token in the request URL or in the request payload.

Note

After expiration (typically about 60 minutes), you will need to obtain a new token manually.

__init__(*, access_token: str | None = None) None[source]#

Initialize the ManualCopilotAuthenticator with a pre-obtained access token.

Parameters:

access_token (Optional[str]) – A valid JWT access token for Microsoft Copilot. This token can be obtained from browser DevTools when connected to Copilot. If None, the token will be read from the COPILOT_ACCESS_TOKEN environment variable.

Raises:
  • ValueError – If no access token is provided either directly or via the environment variable.

  • ValueError – If the provided access token cannot be decoded as a JWT or is missing required claims.

Methods

__init__(*[, access_token])

Initialize the ManualCopilotAuthenticator with a pre-obtained access token.

get_claims()

Get the JWT claims from the access token.

get_token()

Get the current authentication token synchronously.

get_token_async()

Get the current authentication token.

refresh_token()

Not supported by this authenticator.

refresh_token_async()

Not supported by this authenticator.

Attributes

ACCESS_TOKEN_ENV_VAR

Environment variable name for the Copilot access token

token

ACCESS_TOKEN_ENV_VAR: str = 'COPILOT_ACCESS_TOKEN'#

Environment variable name for the Copilot access token

async get_claims() dict[str, Any][source]#

Get the JWT claims from the access token.

Returns:

The JWT claims decoded from the access token.

Return type:

dict[str, Any]

get_token() str[source]#

Get the current authentication token synchronously.

Returns:

The access token provided during initialization.

Return type:

str

async get_token_async() str[source]#

Get the current authentication token.

Returns:

The access token provided during initialization.

Return type:

str

refresh_token() str[source]#

Not supported by this authenticator.

Raises:

RuntimeError – Always raised as manual tokens cannot be refreshed automatically.

async refresh_token_async() str[source]#

Not supported by this authenticator.

Raises:

RuntimeError – Always raised as manual tokens cannot be refreshed automatically.