|
2 | 2 |
|
3 | 3 | from microsoft.agents.authorization import ( |
4 | 4 | AuthenticationConstants, |
| 5 | + AnonymousTokenProvider, |
5 | 6 | ClaimsIdentity, |
6 | 7 | Connections, |
7 | 8 | ) |
|
15 | 16 |
|
16 | 17 |
|
17 | 18 | class RestChannelServiceClientFactory(ChannelServiceClientFactoryBase): |
| 19 | + _ANONYMOUS_TOKEN_PROVIDER = AnonymousTokenProvider() |
| 20 | + |
18 | 21 | def __init__( |
19 | 22 | self, |
20 | 23 | configuration: Any, |
@@ -43,22 +46,31 @@ async def create_connector_client( |
43 | 46 | "RestChannelServiceClientFactory.create_connector_client: audience can't be None or Empty" |
44 | 47 | ) |
45 | 48 |
|
| 49 | + token_provider = ( |
| 50 | + self._connections.get_token_provider(claims_identity, service_url) |
| 51 | + if not use_anonymous |
| 52 | + else self._ANONYMOUS_TOKEN_PROVIDER |
| 53 | + ) |
| 54 | + |
46 | 55 | return ConnectorClient( |
47 | 56 | endpoint=service_url, |
48 | | - credential_token_provider=self._connections.get_token_provider( |
49 | | - claims_identity, service_url |
50 | | - ), |
| 57 | + credential_token_provider=token_provider, |
51 | 58 | credential_resource_url=audience, |
52 | 59 | credential_scopes=scopes, |
53 | 60 | ) |
54 | 61 |
|
55 | 62 | async def create_user_token_client( |
56 | 63 | self, claims_identity: ClaimsIdentity, use_anonymous: bool = False |
57 | 64 | ) -> UserTokenClient: |
58 | | - return UserTokenClient( |
59 | | - credential_token_provider=self._connections.get_token_provider( |
| 65 | + token_provider = ( |
| 66 | + self._connections.get_token_provider( |
60 | 67 | claims_identity, self._token_service_endpoint |
61 | | - ), |
| 68 | + ) |
| 69 | + if not use_anonymous |
| 70 | + else self._ANONYMOUS_TOKEN_PROVIDER |
| 71 | + ) |
| 72 | + return UserTokenClient( |
| 73 | + credential_token_provider=token_provider, |
62 | 74 | credential_resource_url=self._token_service_audience, |
63 | 75 | credential_scopes=[f"{self._token_service_audience}/.default"], |
64 | 76 | endpoint=self._token_service_endpoint, |
|
0 commit comments