Skip to content

Commit 5a59087

Browse files
Reorganizing OAuth Flow (#99)
* Changed default cloud for ConnectionSettings to be PROD * New draft implementations for classes to rework authorization * Revising oauth refactor with new proposed architecture * Adding code to connect to AgentApp * Generating new unit tests * Filling in test cases for OAuthFlow and models * Adding more tests * Fixing test cases and catching bugs * Another commit * Finishing flow storage client and auth flow tests * Adding more authorization tests * Adding documentation * Added more Authorizationt tests and fixed inconsistencies in storage client * Renaming, restructing, and revising imports * Passing all Authorization unit tests * Cleaning code and removing unused args * Fixing test cases and implementing cached client * Added refresh() and adjusted tests * Aligned more test cases * Fixed expiration time handling * Changed magic_code keyword to code in tests * Fixed expiration time issue * Undid TokenResponse changes * Updated logging * Adding some comments * Removed unused cache field * Added back the __bool__ op on TokenResponse * Revised some comments * Updated default flow duration to 10 minutes * Changing default flow duration * Reformatted with black * Added pytest-mock as a dependency
1 parent e77701e commit 5a59087

24 files changed

Lines changed: 4040 additions & 2169 deletions

.azdo/ci-pr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ steps:
2626

2727
- script: |
2828
python -m pip install --upgrade pip
29-
python -m pip install flake8 pytest black pytest-asyncio build setuptools-git-versioning
29+
python -m pip install flake8 pytest pytest-mock black pytest-asyncio build setuptools-git-versioning
3030
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
3131
displayName: 'Install dependencies'
3232

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Install dependencies
3131
run: |
3232
python -m pip install --upgrade pip
33-
python -m pip install flake8 pytest black pytest-asyncio build setuptools-git-versioning
33+
python -m pip install flake8 pytest pytest-mock black pytest-asyncio build setuptools-git-versioning
3434
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
3535
- name: Check format with black
3636
run: |

libraries/microsoft-agents-activity/microsoft/agents/activity/token_response.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ class TokenResponse(AgentsModel):
2323
token: NonEmptyString = None
2424
expiration: NonEmptyString = None
2525
channel_id: NonEmptyString = None
26+
27+
def __bool__(self):
28+
return bool(self.token)

libraries/microsoft-agents-hosting-core/microsoft/agents/hosting/core/__init__.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from .activity_handler import ActivityHandler
22
from .agent import Agent
3-
from .oauth_flow import OAuthFlow
43
from .card_factory import CardFactory
54
from .channel_adapter import ChannelAdapter
65
from .channel_api_handler_protocol import ChannelApiHandlerProtocol
@@ -20,12 +19,11 @@
2019
from .app.route import Route, RouteHandler
2120
from .app.typing_indicator import TypingIndicator
2221

23-
# OAuth
24-
from .app.oauth.authorization import (
22+
# App Auth
23+
from .app.oauth import (
2524
Authorization,
2625
AuthorizationHandlers,
2726
AuthHandler,
28-
SignInState,
2927
)
3028

3129
# App State
@@ -44,6 +42,16 @@
4442
from .authorization.jwt_token_validator import JwtTokenValidator
4543
from .authorization.auth_types import AuthTypes
4644

45+
# OAuth
46+
from .oauth import (
47+
FlowState,
48+
FlowStateTag,
49+
FlowErrorTag,
50+
FlowResponse,
51+
FlowStorageClient,
52+
OAuthFlow,
53+
)
54+
4755
# Client API
4856
from .client.agent_conversation_reference import AgentConversationReference
4957
from .client.channel_factory_protocol import ChannelFactoryProtocol
@@ -88,7 +96,6 @@
8896
__all__ = [
8997
"ActivityHandler",
9098
"Agent",
91-
"OAuthFlow",
9299
"CardFactory",
93100
"ChannelAdapter",
94101
"ChannelApiHandlerProtocol",
@@ -155,4 +162,10 @@
155162
"StoreItem",
156163
"Storage",
157164
"MemoryStorage",
165+
"FlowState",
166+
"FlowStateTag",
167+
"FlowErrorTag",
168+
"FlowResponse",
169+
"FlowStorageClient",
170+
"OAuthFlow",
158171
]

libraries/microsoft-agents-hosting-core/microsoft/agents/hosting/core/app/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
from .route import Route, RouteHandler
1414
from .typing_indicator import TypingIndicator
1515

16-
# OAuth
17-
from .oauth.authorization import (
16+
# Auth
17+
from .oauth import (
1818
Authorization,
19-
AuthorizationHandlers,
2019
AuthHandler,
21-
SignInState,
20+
AuthorizationHandlers,
2221
)
2322

2423
# App State
@@ -49,7 +48,6 @@
4948
"TurnState",
5049
"TempState",
5150
"Authorization",
52-
"AuthorizationHandlers",
5351
"AuthHandler",
54-
"SignInState",
52+
"AuthorizationHandlers",
5553
]

0 commit comments

Comments
 (0)