Skip to content

Conversation

MehakBindra
Copy link
Contributor

@MehakBindra MehakBindra commented Sep 5, 2025

Minor change to allow users to pass their own token methods

For eg:

def create_token_factory():
    Create a token factory for authentication.
    async def get_token(scope: Union[str, List[str]], tenant_id: Optional[str] = None) -> str:
        managedIdentityCredential = ManagedIdentityCredential(
            client_id=os.getenv("CLIENT_ID")
        )
        scopes = [scope] if isinstance(scope, str) else scope
        token = managedIdentityCredential.get_token(*scopes, tenant_id=tenant_id)
        return token.token
    return get_token

app = App(token = create_token_factory())

@Copilot Copilot AI review requested due to automatic review settings September 5, 2025 23:18
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for custom token authentication methods by introducing a new token field to the AppOptions configuration. This allows applications to provide their own token generation functions instead of relying solely on client credentials.

  • Adds a token field to both AppOptions TypedDict and InternalAppOptions dataclass
  • Updates the credential initialization logic to support TokenCredentials when a token function is provided
  • Imports necessary types to support the new token callback function signature

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/apps/src/microsoft/teams/apps/options.py Adds token field definition and imports required types
packages/apps/src/microsoft/teams/apps/app.py Implements token credential initialization logic and imports TokenCredentials

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Collaborator

@heyitsaamir heyitsaamir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, could you add a test, and a comment explaining what it is? I think we should probably also comment on all the AppOptions... but atleast start with this one :)

@MehakBindra MehakBindra merged commit 6e22d99 into main Sep 6, 2025
3 checks passed
@MehakBindra MehakBindra deleted the mehak/tokenCredentials branch September 6, 2025 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants