8000 Merge branch 'master' into emimunoz/luisV3-recognizer · ericmicrofocus/botbuilder-python@ef3a09e · GitHub
[go: up one dir, main page]

Skip to content

Commit ef3a09e

Browse files
committed
Merge branch 'master' into emimunoz/luisV3-recognizer
2 parents 07ddc1d + ec9f9d1 commit ef3a09e

File tree

10 files changed

+265
-137
lines changed

10 files changed

+265
-137
lines changed

libraries/botbuilder-core/botbuilder/core/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
from .card_factory import CardFactory
2020
from .channel_service_handler import BotActionNotImplementedError, ChannelServiceHandler
2121
from .conversation_state import ConversationState
22-
from .extended_user_token_provider import ExtendedUserTokenProvider
22+
from .oauth.extended_user_token_provider import ExtendedUserTokenProvider
23+
from .oauth.user_token_provider import UserTokenProvider
2324
from .intent_score import IntentScore
2425
from .invoke_response import InvokeResponse
2526
from .memory_storage import MemoryStorage
@@ -39,7 +40,6 @@
3940
from .telemetry_logger_middleware import TelemetryLoggerMiddleware
4041
from .turn_context import TurnContext
4142
from .user_state import UserState
42-
from .user_token_provider import UserTokenProvider
4343
from .register_class_middleware import RegisterClassMiddleware
4444
from .adapter_extensions import AdapterExtensions
4545
from .healthcheck import HealthCheck

libraries/botbuilder-core/botbuilder/core/adapters/test_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
)
3131
from ..bot_adapter import BotAdapter
3232
from ..turn_context import TurnContext
33-
from ..extended_user_token_provider import ExtendedUserTokenProvider
33+
from ..oauth.extended_user_token_provider import ExtendedUserTokenProvider
3434

3535

3636
class UserToken:

libraries/botbuilder-core/botbuilder/core/bot_framework_adapter.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@
5353

5454
from . import __version__
5555
from .bot_adapter import BotAdapter
56+
from .oauth import (
57+
ConnectorClientBuilder,
58+
ExtendedUserTokenProvider,
59+
)
5660
from .turn_context import TurnContext
57-
from .extended_user_token_provider import ExtendedUserTokenProvider
5861
from .invoke_response import InvokeResponse
5962
from .conversation_reference_extension import get_continuation_activity
6063

@@ -164,7 +167,9 @@ def __init__(
164167
)
165168

166169

167-
class BotFrameworkAdapter(BotAdapter, ExtendedUserTokenProvider):
170+
class BotFrameworkAdapter(
171+
BotAdapter, ExtendedUserTokenProvider, ConnectorClientBuilder
172+
):
168173
"""
169174
Defines an adapter to connect a bot to a service endpoint.
170175
@@ -1083,7 +1088,8 @@ async def create_connector_client(
10831088
self, service_url: str, identity: ClaimsIdentity = None, audience: str = None
10841089
) -> ConnectorClient:
10851090
"""
1086-
Creates the connector client
1091+
Implementation of ConnectorClientProvider.create_connector_client.
1092+
10871093
:param service_url: The service URL
10881094
:param identity: The claims identity
10891095
:param audience:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
from .extended_user_token_provider import ExtendedUserTokenProvider
5+
from .user_token_provider import UserTokenProvider
6+
from .connector_client_builder import ConnectorClientBuilder
7+
8+
__all__ = [
9+
"ConnectorClientBuilder",
10+
"ExtendedUserTokenProvider",
11+
"UserTokenProvider",
12+
]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
from abc import ABC, abstractmethod
4+
5+
from botframework.connector import ConnectorClient
6+
from botframework.connector.auth import ClaimsIdentity
7+
8+
9+
class ConnectorClientBuilder(ABC):
10+
"""
11+
Abstraction to build connector clients.
12+
"""
13+
14+
@abstractmethod
15+
async def create_connector_client(
16+
self, service_url: str, identity: ClaimsIdentity = None, audience: str = None
17+
) -> ConnectorClient:
18+
"""
19+
Creates the connector client asynchronous.
20+
21+
:param service_url: The service URL.
22+
:param identity: The claims claimsIdentity.
23+
:param audience: The target audience for the connector.
24+
:return: ConnectorClient instance
25+
"""
26+
raise NotImplementedError()

libraries/botbuilder-core/botbuilder/core/extended_user_token_provider.py renamed to libraries/botbuilder-core/botbuilder/core/oauth/extended_user_token_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
)
1212
from botframework.connector.auth import AppCredentials
1313

14-
from .turn_context import TurnContext
14+
from botbuilder.core.turn_context import TurnContext
1515
from .user_token_provider import UserTokenProvider
1616

1717

Original file line numberDiff line numberDiff line change
@@ -1,113 +1,112 @@
1-
# Copyright (c) Microsoft Corporation. All rights reserved.
2-
# Licensed under the MIT License.
3-
4-
from abc import ABC, abstractmethod
5-
from typing import Dict, List
6-
7-
from botbuilder.schema import TokenResponse
8-
from botframework.connector.auth import AppCredentials
9-
10-
from .turn_context import TurnContext
11-
12-
13-
class UserTokenProvider(ABC):
14-
@abstractmethod
15-
async def get_user_token(
16-
self,
17-
context: TurnContext,
18-
connection_name: str,
19-
magic_code: str = None,
20-
oauth_app_credentials: AppCredentials = None,
21-
) -> TokenResponse:
22-
"""
23-
Retrieves the OAuth token for a user that is in a sign-in flow.
24-
:param context: Context for the current turn of conversation with the user.
25-
:param connection_name: Name of the auth connection to use.
26-
:param magic_code: (Optional) Optional user entered code to validate.
27-
:param oauth_app_credentials: (Optional) AppCredentials for OAuth. If None is supplied, the
28-
Bots credentials are used.
29-
:return:
30-
"""
31-
raise NotImplementedError()
32-
33-
@abstractmethod
34-
async def sign_out_user(
35-
self,
36-
context: TurnContext,
37-
connection_name: str = None,
38-
user_id: str = None,
39-
oauth_app_credentials: AppCredentials = None,
40-
):
41-
"""
42-
Signs the user out with the token server.
43-
:param context: Context for the current turn of conversation with the user.
44-
:param connection_name: Name of the auth connection to use.
45-
:param user_id: User id of user to sign out.
46-
:param oauth_app_credentials: (Optional) AppCredentials for OAuth. If None is supplied, the
47-
Bots credentials are used.
48-
:return:
49-
"""
50-
raise NotImplementedError()
51-
52-
@abstractmethod
53-
async def get_oauth_sign_in_link(
54-
self,
55-
context: TurnContext,
56-
connection_name: str,
57-
final_redirect: str = None,
58-
oauth_app_credentials: AppCredentials = None,
59-
) -> str:
60-
"""
61-
Get the raw signin link to be sent to the user for signin for a connection name.
62-
:param context: Context for the current turn of conversation with the user.
63-
:param connection_name: Name of the auth connection to use.
64-
:param final_redirect: The final URL that the OAuth flow will redirect to.
65-
:param oauth_app_credentials: (Optional) AppCredentials for OAuth. If None is supplied, the
66-
Bots credentials are used.
67-
:return:
68-
"""
69-
raise NotImplementedError()
70-
71-
@abstractmethod
72-
async def get_token_status(
73-
self,
74-
context: TurnContext,
75-
connection_name: str = None,
76-
user_id: str = None,
77-
include_filter: str = None,
78-
oauth_app_credentials: AppCredentials = None,
79-
) -> Dict[str, TokenResponse]:
80-
"""
81-
Retrieves Azure Active Directory tokens for particular resources on a configured connection.
82-
:param context: Context for the current turn of conversation with the user.
83-
:param connection_name: Name of the auth connection to use.
84-
:param user_id: The user Id for which token status is retrieved.
85-
:param include_filter: Optional comma separated list of connection's to include. Blank will return token status
86-
for all configured connections.
87-
:param oauth_app_credentials: (Optional) AppCredentials for OAuth. If None is supplied, the
88-
Bots credentials are used.
89-
:return:
90-
"""
91-
raise NotImplementedError()
92-
93-
@abstractmethod
94-
async def get_aad_tokens(
95-
self,
96-
context: TurnContext,
97-
connection_name: str,
98-
resource_urls: List[str],
99-
user_id: str = None,
100-
oauth_app_credentials: AppCredentials = None,
101-
) -> Dict[str, TokenResponse]:
102-
"""
103-
Retrieves Azure Active Directory tokens for particular resources on a configured connection.
104-
:param context: Context for the current turn of conversation with the user.
105-
:param connection_name: Name of the auth connection to use.
106-
:param resource_urls: The list of resource URLs to retrieve tokens for.
107-
:param user_id: The user Id for which tokens are retrieved. If passing in None the userId is taken
108-
from the Activity in the TurnContext.
109-
:param oauth_app_credentials: (Optional) AppCredentials for OAuth. If None is supplied, the
110-
Bots credentials are used.
111-
:return:
112-
"""
113-
raise NotImplementedError()
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
from abc import ABC, abstractmethod
5+
from typing import Dict, List
6+
7+
from botbuilder.core.turn_context import TurnContext
8+
from botbuilder.schema import TokenResponse
9+
from botframework.connector.auth import AppCredentials
10+
11+
12+
class UserTokenProvider(ABC):
13+
@abstractmethod
14+
async def get_user_token(
15+
self,
16+
context: TurnContext,
17+
connection_name: str,
18+
magic_code: str = None,
19+
oauth_app_credentials: AppCredentials = None,
20+
) -> TokenResponse:
21+
"""
22+
Retrieves the OAuth token for a user that is in a sign-in flow.
23+
:param context: Context for the current turn of conversation with the user.
24+
:param connection_name: Name of the auth connection to use.
25+
:param magic_code: (Optional) Optional user entered code to validate.
26+
:param oauth_app_credentials: (Optional) AppCredentials for OAuth. If None is supplied, the
27+
Bots credentials are used.
28+
:return:
29+
"""
30+
raise NotImplementedError()
31+
32+
@abstractmethod
33+
async def sign_out_user(
34+
self,
35+
context: TurnContext,
36+
connection_name: str = None,
37+
user_id: str = None,
38+
oauth_app_credentials: AppCredentials = None,
39+
):
40+
"""
41+
Signs the user out with the token server.
42+
:param context: Context for the current turn of conversation with the user.
43+
:param connection_name: Name of the auth connection to use.
44+
:param user_id: User id of user to sign out.
45+
:param oauth_app_credentials: (Optional) AppCredentials for OAuth. If None is supplied, the
46+
Bots credentials are used.
47+
:return:
48+
"""
49+
raise NotImplementedError()
50+
51+
@abstractmethod
52+
async def get_oauth_sign_in_link(
53+
self,
54+
context: TurnContext,
55+
connection_name: str,
56+
final_redirect: str = None,
57+
oauth_app_credentials: AppCredentials = None,
58+
) -> str:
59+
"""
60+
Get the raw signin link to be sent to the user for signin for a connection name.
61+
:param context: Context for the current turn of conversation with the user.
62+
:param connection_name: Name of the auth connection to use.
63+
:param final_redirect: The final URL that the OAuth flow will redirect to.
64+
:param oauth_app_credentials: (Optional) AppCredentials for OAuth. If None is supplied, the
65+
Bots credentials are used.
66+
:return:
67+
"""
68+
raise NotImplementedError()
69+
70+
@abstractmethod
71+
async def get_token_status(
72+
self,
73+
context: TurnContext,
74+
connection_name: str = None,
75+
user_id: str = None,
76+
include_filter: str = None,
77+
oauth_app_credentials: AppCredentials = None,
78+
) -> Dict[str, TokenResponse]:
79+
"""
80+
Retrieves Azure Active Directory tokens for particular resources on a configured connection.
81+
:param context: Context for the current turn of conversation with the user.
82+
:param connection_name: Name of the auth connection to use.
83+
:param user_id: The user Id for which token status is retrieved.
84+
:param include_filter: Optional comma separated list of connection's to include. Blank will return token status
85+
for all configured connections.
86+
:param oauth_app_credentials: (Optional) AppCredentials for OAuth. If None is supplied, the
87+
Bots credentials are used.
88+
:return:
89+
"""
90+
raise NotImplementedError()
91+
92+
@abstractmethod
93+
async def get_aad_tokens(
94+
self,
95+
context: TurnContext,
96+
connection_name: str,
97+
resource_urls: List[str],
98+
user_id: str = None,
99+
oauth_app_credentials: AppCredentials = None,
100+
) -> Dict[str, TokenResponse]:
101+
"""
102+
Retrieves Azure Active Directory tokens for particular resources on a configured connection.
103+
:param context: Context for the current turn of conversation with the user.
104+
:param connection_name: Name of the auth connection to use.
105+
:param resource_urls: The list of resource URLs to retrieve tokens for.
106+
:param user_id: The user Id for which tokens are retrieved. If passing in None the userId is taken
107+
from the Activity in the TurnContext.
108+
:param oauth_app_credentials: (Optional) AppCredentials for OAuth. If None is supplied, the
109+
Bots credentials are used.
110+
:return:
111+
"""
112+
raise NotImplementedError()

0 commit comments

Comments
 (0)
0