|
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