pyrit.auth.ManualCopilotAuthenticator#
- class ManualCopilotAuthenticator(*, access_token: str | None = None)[source]#
Bases:
AuthenticatorSimple 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:
Open the Copilot webapp (e.g., https://m365.cloud.microsoft/chat) in a browser.
Open DevTools (F12 or Ctrl+Shift+I).
Go to the Network tab.
Filter by “Socket” connections or search for “Chathub”.
Start typing in the chat to initiate a WebSocket connection.
Look for the latest WebSocket connection to
substrate.office.com/m365Copilot/Chathub.You may find the
access_tokenin 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_TOKENenvironment 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 the JWT claims from the access token.
Get the current authentication token synchronously.
Get the current authentication token.
Not supported by this authenticator.
Not supported by this authenticator.
Attributes
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
- get_token() str[source]#
Get the current authentication token synchronously.
- Returns:
The access token provided during initialization.
- Return type:
- async get_token_async() str[source]#
Get the current authentication token.
- Returns:
The access token provided during initialization.
- Return type:
- 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.