@microsoft/agents-hosting 0.1.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -0
- package/dist/src/activityHandler.d.ts +108 -0
- package/dist/src/activityHandler.js +395 -0
- package/dist/src/activityHandler.js.map +1 -0
- package/dist/src/agent-client/agentClient.d.ts +13 -0
- package/dist/src/agent-client/agentClient.js +75 -0
- package/dist/src/agent-client/agentClient.js.map +1 -0
- package/dist/src/agent-client/expressApi.d.ts +4 -0
- package/dist/src/agent-client/expressApi.js +50 -0
- package/dist/src/agent-client/expressApi.js.map +1 -0
- package/dist/src/agent-client/index.d.ts +2 -0
- package/dist/src/agent-client/index.js +19 -0
- package/dist/src/agent-client/index.js.map +1 -0
- package/dist/src/app/agentApplication.d.ts +47 -0
- package/dist/src/app/agentApplication.js +317 -0
- package/dist/src/app/agentApplication.js.map +1 -0
- package/dist/src/app/appRoute.d.ts +11 -0
- package/dist/src/app/appRoute.js +7 -0
- package/dist/src/app/appRoute.js.map +1 -0
- package/dist/src/app/applicationBuilder.d.ts +18 -0
- package/dist/src/app/applicationBuilder.js +37 -0
- package/dist/src/app/applicationBuilder.js.map +1 -0
- package/dist/src/app/applicationOptions.d.ts +19 -0
- package/dist/src/app/applicationOptions.js +7 -0
- package/dist/src/app/applicationOptions.js.map +1 -0
- package/dist/src/app/attachmentDownloader.d.ts +13 -0
- package/dist/src/app/attachmentDownloader.js +72 -0
- package/dist/src/app/attachmentDownloader.js.map +1 -0
- package/dist/src/app/conversationUpdateEvents.d.ts +5 -0
- package/dist/src/app/conversationUpdateEvents.js +7 -0
- package/dist/src/app/conversationUpdateEvents.js.map +1 -0
- package/dist/src/app/index.d.ts +10 -0
- package/dist/src/app/index.js +27 -0
- package/dist/src/app/index.js.map +1 -0
- package/dist/src/app/inputFileDownloader.d.ts +14 -0
- package/dist/src/app/inputFileDownloader.js +7 -0
- package/dist/src/app/inputFileDownloader.js.map +1 -0
- package/dist/src/app/memory.d.ts +10 -0
- package/dist/src/app/memory.js +7 -0
- package/dist/src/app/memory.js.map +1 -0
- package/dist/src/app/oauth/authenticationOptions.d.ts +7 -0
- package/dist/src/app/oauth/authenticationOptions.js +7 -0
- package/dist/src/app/oauth/authenticationOptions.js.map +1 -0
- package/dist/src/app/oauth/webChatOAuthFlowAppStyle.d.ts +11 -0
- package/dist/src/app/oauth/webChatOAuthFlowAppStyle.js +85 -0
- package/dist/src/app/oauth/webChatOAuthFlowAppStyle.js.map +1 -0
- package/dist/src/app/routeHandler.d.ts +7 -0
- package/dist/src/app/routeHandler.js +7 -0
- package/dist/src/app/routeHandler.js.map +1 -0
- package/dist/src/app/routeSelector.d.ts +7 -0
- package/dist/src/app/routeSelector.js +7 -0
- package/dist/src/app/routeSelector.js.map +1 -0
- package/dist/src/app/turnEvents.d.ts +5 -0
- package/dist/src/app/turnEvents.js +7 -0
- package/dist/src/app/turnEvents.js.map +1 -0
- package/dist/src/app/turnState.d.ts +85 -0
- package/dist/src/app/turnState.js +274 -0
- package/dist/src/app/turnState.js.map +1 -0
- package/dist/src/app/turnStateEntry.d.ts +17 -0
- package/dist/src/app/turnStateEntry.js +39 -0
- package/dist/src/app/turnStateEntry.js.map +1 -0
- package/dist/src/auth/authConfiguration.d.ts +29 -0
- package/dist/src/auth/authConfiguration.js +58 -0
- package/dist/src/auth/authConfiguration.js.map +1 -0
- package/dist/src/auth/authProvider.d.ts +17 -0
- package/dist/src/auth/authProvider.js +7 -0
- package/dist/src/auth/authProvider.js.map +1 -0
- package/dist/src/auth/index.d.ts +4 -0
- package/dist/src/auth/index.js +21 -0
- package/dist/src/auth/index.js.map +1 -0
- package/dist/src/auth/jwt-middleware.d.ts +13 -0
- package/dist/src/auth/jwt-middleware.js +97 -0
- package/dist/src/auth/jwt-middleware.js.map +1 -0
- package/dist/src/auth/msalTokenProvider.d.ts +53 -0
- package/dist/src/auth/msalTokenProvider.js +198 -0
- package/dist/src/auth/msalTokenProvider.js.map +1 -0
- package/dist/src/auth/request.d.ts +15 -0
- package/dist/src/auth/request.js +7 -0
- package/dist/src/auth/request.js.map +1 -0
- package/dist/src/baseAdapter.d.ts +88 -0
- package/dist/src/baseAdapter.js +94 -0
- package/dist/src/baseAdapter.js.map +1 -0
- package/dist/src/cards/animationCard.d.ts +36 -0
- package/dist/src/cards/animationCard.js +7 -0
- package/dist/src/cards/animationCard.js.map +1 -0
- package/dist/src/cards/audioCard.d.ts +36 -0
- package/dist/src/cards/audioCard.js +7 -0
- package/dist/src/cards/audioCard.js.map +1 -0
- package/dist/src/cards/cardFactory.d.ts +123 -0
- package/dist/src/cards/cardFactory.js +225 -0
- package/dist/src/cards/cardFactory.js.map +1 -0
- package/dist/src/cards/cardImage.d.ts +16 -0
- package/dist/src/cards/cardImage.js +7 -0
- package/dist/src/cards/cardImage.js.map +1 -0
- package/dist/src/cards/fact.d.ts +13 -0
- package/dist/src/cards/fact.js +7 -0
- package/dist/src/cards/fact.js.map +1 -0
- package/dist/src/cards/heroCard.d.ts +23 -0
- package/dist/src/cards/heroCard.js +7 -0
- package/dist/src/cards/heroCard.js.map +1 -0
- package/dist/src/cards/index.d.ts +17 -0
- package/dist/src/cards/index.js +34 -0
- package/dist/src/cards/index.js.map +1 -0
- package/dist/src/cards/mediaUrl.d.ts +17 -0
- package/dist/src/cards/mediaUrl.js +7 -0
- package/dist/src/cards/mediaUrl.js.map +1 -0
- package/dist/src/cards/o365ConnectorCard.d.ts +35 -0
- package/dist/src/cards/o365ConnectorCard.js +7 -0
- package/dist/src/cards/o365ConnectorCard.js.map +1 -0
- package/dist/src/cards/o365ConnectorCardActionBase.d.ts +22 -0
- package/dist/src/cards/o365ConnectorCardActionBase.js +7 -0
- package/dist/src/cards/o365ConnectorCardActionBase.js.map +1 -0
- package/dist/src/cards/o365ConnectorCardFact.d.ts +17 -0
- package/dist/src/cards/o365ConnectorCardFact.js +7 -0
- package/dist/src/cards/o365ConnectorCardFact.js.map +1 -0
- package/dist/src/cards/o365ConnectorCardImage.d.ts +17 -0
- package/dist/src/cards/o365ConnectorCardImage.js +7 -0
- package/dist/src/cards/o365ConnectorCardImage.js.map +1 -0
- package/dist/src/cards/o365ConnectorCardSection.d.ts +57 -0
- package/dist/src/cards/o365ConnectorCardSection.js +7 -0
- package/dist/src/cards/o365ConnectorCardSection.js.map +1 -0
- package/dist/src/cards/receiptCard.d.ts +44 -0
- package/dist/src/cards/receiptCard.js +7 -0
- package/dist/src/cards/receiptCard.js.map +1 -0
- package/dist/src/cards/receiptItem.d.ts +39 -0
- package/dist/src/cards/receiptItem.js +7 -0
- package/dist/src/cards/receiptItem.js.map +1 -0
- package/dist/src/cards/signinCard.d.ts +14 -0
- package/dist/src/cards/signinCard.js +5 -0
- package/dist/src/cards/signinCard.js.map +1 -0
- package/dist/src/cards/taskModuleAction.d.ts +43 -0
- package/dist/src/cards/taskModuleAction.js +30 -0
- package/dist/src/cards/taskModuleAction.js.map +1 -0
- package/dist/src/cards/thumbnailCard.d.ts +35 -0
- package/dist/src/cards/thumbnailCard.js +7 -0
- package/dist/src/cards/thumbnailCard.js.map +1 -0
- package/dist/src/cards/thumbnailUrl.d.ts +17 -0
- package/dist/src/cards/thumbnailUrl.js +7 -0
- package/dist/src/cards/thumbnailUrl.js.map +1 -0
- package/dist/src/cards/videoCard.d.ts +60 -0
- package/dist/src/cards/videoCard.js +7 -0
- package/dist/src/cards/videoCard.js.map +1 -0
- package/dist/src/claimsIdentity.d.ts +35 -0
- package/dist/src/claimsIdentity.js +43 -0
- package/dist/src/claimsIdentity.js.map +1 -0
- package/dist/src/cloudAdapter.d.ts +128 -0
- package/dist/src/cloudAdapter.js +376 -0
- package/dist/src/cloudAdapter.js.map +1 -0
- package/dist/src/connector-client/attachmentData.d.ts +25 -0
- package/dist/src/connector-client/attachmentData.js +7 -0
- package/dist/src/connector-client/attachmentData.js.map +1 -0
- package/dist/src/connector-client/attachmentInfo.d.ts +22 -0
- package/dist/src/connector-client/attachmentInfo.js +7 -0
- package/dist/src/connector-client/attachmentInfo.js.map +1 -0
- package/dist/src/connector-client/attachmentView.d.ts +17 -0
- package/dist/src/connector-client/attachmentView.js +7 -0
- package/dist/src/connector-client/attachmentView.js.map +1 -0
- package/dist/src/connector-client/connectorClient.d.ts +93 -0
- package/dist/src/connector-client/connectorClient.js +249 -0
- package/dist/src/connector-client/connectorClient.js.map +1 -0
- package/dist/src/connector-client/conversationMembers.d.ts +18 -0
- package/dist/src/connector-client/conversationMembers.js +7 -0
- package/dist/src/connector-client/conversationMembers.js.map +1 -0
- package/dist/src/connector-client/conversationParameters.d.ts +38 -0
- package/dist/src/connector-client/conversationParameters.js +7 -0
- package/dist/src/connector-client/conversationParameters.js.map +1 -0
- package/dist/src/connector-client/conversationResourceResponse.d.ts +21 -0
- package/dist/src/connector-client/conversationResourceResponse.js +7 -0
- package/dist/src/connector-client/conversationResourceResponse.js.map +1 -0
- package/dist/src/connector-client/conversationsResult.d.ts +18 -0
- package/dist/src/connector-client/conversationsResult.js +7 -0
- package/dist/src/connector-client/conversationsResult.js.map +1 -0
- package/dist/src/connector-client/index.d.ts +9 -0
- package/dist/src/connector-client/index.js +26 -0
- package/dist/src/connector-client/index.js.map +1 -0
- package/dist/src/connector-client/resourceResponse.d.ts +13 -0
- package/dist/src/connector-client/resourceResponse.js +7 -0
- package/dist/src/connector-client/resourceResponse.js.map +1 -0
- package/dist/src/index.d.ts +26 -0
- package/dist/src/index.js +45 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/invoke/adaptiveCardAuthentication.d.ts +10 -0
- package/dist/src/invoke/adaptiveCardAuthentication.js +7 -0
- package/dist/src/invoke/adaptiveCardAuthentication.js.map +1 -0
- package/dist/src/invoke/adaptiveCardInvokeResponse.d.ts +21 -0
- package/dist/src/invoke/adaptiveCardInvokeResponse.js +7 -0
- package/dist/src/invoke/adaptiveCardInvokeResponse.js.map +1 -0
- package/dist/src/invoke/adaptiveCardInvokeValue.d.ts +23 -0
- package/dist/src/invoke/adaptiveCardInvokeValue.js +7 -0
- package/dist/src/invoke/adaptiveCardInvokeValue.js.map +1 -0
- package/dist/src/invoke/index.d.ts +9 -0
- package/dist/src/invoke/index.js +26 -0
- package/dist/src/invoke/index.js.map +1 -0
- package/dist/src/invoke/invokeException.d.ts +24 -0
- package/dist/src/invoke/invokeException.js +35 -0
- package/dist/src/invoke/invokeException.js.map +1 -0
- package/dist/src/invoke/invokeResponse.d.ts +17 -0
- package/dist/src/invoke/invokeResponse.js +7 -0
- package/dist/src/invoke/invokeResponse.js.map +1 -0
- package/dist/src/invoke/searchInvokeOptions.d.ts +17 -0
- package/dist/src/invoke/searchInvokeOptions.js +7 -0
- package/dist/src/invoke/searchInvokeOptions.js.map +1 -0
- package/dist/src/invoke/searchInvokeResponse.d.ts +10 -0
- package/dist/src/invoke/searchInvokeResponse.js +7 -0
- package/dist/src/invoke/searchInvokeResponse.js.map +1 -0
- package/dist/src/invoke/searchInvokeValue.d.ts +26 -0
- package/dist/src/invoke/searchInvokeValue.js +7 -0
- package/dist/src/invoke/searchInvokeValue.js.map +1 -0
- package/dist/src/invoke/tokenExchangeInvokeRequest.d.ts +21 -0
- package/dist/src/invoke/tokenExchangeInvokeRequest.js +7 -0
- package/dist/src/invoke/tokenExchangeInvokeRequest.js.map +1 -0
- package/dist/src/logger.d.ts +12 -0
- package/dist/src/logger.js +42 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/messageFactory.d.ts +62 -0
- package/dist/src/messageFactory.js +143 -0
- package/dist/src/messageFactory.js.map +1 -0
- package/dist/src/middlewareSet.d.ts +43 -0
- package/dist/src/middlewareSet.js +57 -0
- package/dist/src/middlewareSet.js.map +1 -0
- package/dist/src/oauth/index.d.ts +7 -0
- package/dist/src/oauth/index.js +24 -0
- package/dist/src/oauth/index.js.map +1 -0
- package/dist/src/oauth/oauthCard.d.ts +28 -0
- package/dist/src/oauth/oauthCard.js +5 -0
- package/dist/src/oauth/oauthCard.js.map +1 -0
- package/dist/src/oauth/signingResource.d.ts +19 -0
- package/dist/src/oauth/signingResource.js +5 -0
- package/dist/src/oauth/signingResource.js.map +1 -0
- package/dist/src/oauth/tokenExchangeRequest.d.ts +17 -0
- package/dist/src/oauth/tokenExchangeRequest.js +5 -0
- package/dist/src/oauth/tokenExchangeRequest.js.map +1 -0
- package/dist/src/oauth/tokenExchangeResource.d.ts +17 -0
- package/dist/src/oauth/tokenExchangeResource.js +5 -0
- package/dist/src/oauth/tokenExchangeResource.js.map +1 -0
- package/dist/src/oauth/tokenPostResource.d.ts +9 -0
- package/dist/src/oauth/tokenPostResource.js +5 -0
- package/dist/src/oauth/tokenPostResource.js.map +1 -0
- package/dist/src/oauth/userTokenClient.d.ts +49 -0
- package/dist/src/oauth/userTokenClient.js +117 -0
- package/dist/src/oauth/userTokenClient.js.map +1 -0
- package/dist/src/oauth/webChatOAuthFlow.d.ts +41 -0
- package/dist/src/oauth/webChatOAuthFlow.js +117 -0
- package/dist/src/oauth/webChatOAuthFlow.js.map +1 -0
- package/dist/src/state/agentState.d.ts +71 -0
- package/dist/src/state/agentState.js +122 -0
- package/dist/src/state/agentState.js.map +1 -0
- package/dist/src/state/agentStatePropertyAccesor.d.ts +39 -0
- package/dist/src/state/agentStatePropertyAccesor.js +60 -0
- package/dist/src/state/agentStatePropertyAccesor.js.map +1 -0
- package/dist/src/state/conversationState.d.ts +18 -0
- package/dist/src/state/conversationState.js +38 -0
- package/dist/src/state/conversationState.js.map +1 -0
- package/dist/src/state/index.d.ts +4 -0
- package/dist/src/state/index.js +21 -0
- package/dist/src/state/index.js.map +1 -0
- package/dist/src/state/userState.d.ts +18 -0
- package/dist/src/state/userState.js +38 -0
- package/dist/src/state/userState.js.map +1 -0
- package/dist/src/statusCodes.d.ts +19 -0
- package/dist/src/statusCodes.js +24 -0
- package/dist/src/statusCodes.js.map +1 -0
- package/dist/src/storage/index.d.ts +2 -0
- package/dist/src/storage/index.js +19 -0
- package/dist/src/storage/index.js.map +1 -0
- package/dist/src/storage/memoryStorage.d.ts +50 -0
- package/dist/src/storage/memoryStorage.js +100 -0
- package/dist/src/storage/memoryStorage.js.map +1 -0
- package/dist/src/storage/storage.d.ts +47 -0
- package/dist/src/storage/storage.js +7 -0
- package/dist/src/storage/storage.js.map +1 -0
- package/dist/src/tokenResponseEventName.d.ts +5 -0
- package/dist/src/tokenResponseEventName.js +9 -0
- package/dist/src/tokenResponseEventName.js.map +1 -0
- package/dist/src/transcript/consoleTranscriptLogger.d.ts +13 -0
- package/dist/src/transcript/consoleTranscriptLogger.js +21 -0
- package/dist/src/transcript/consoleTranscriptLogger.js.map +1 -0
- package/dist/src/transcript/index.d.ts +4 -0
- package/dist/src/transcript/index.js +21 -0
- package/dist/src/transcript/index.js.map +1 -0
- package/dist/src/transcript/transcriptLogger.d.ts +42 -0
- package/dist/src/transcript/transcriptLogger.js +3 -0
- package/dist/src/transcript/transcriptLogger.js.map +1 -0
- package/dist/src/transcript/transcriptLoggerMiddleware.d.ts +38 -0
- package/dist/src/transcript/transcriptLoggerMiddleware.js +126 -0
- package/dist/src/transcript/transcriptLoggerMiddleware.js.map +1 -0
- package/dist/src/transcript/transcriptStore.d.ts +30 -0
- package/dist/src/transcript/transcriptStore.js +3 -0
- package/dist/src/transcript/transcriptStore.js.map +1 -0
- package/dist/src/turnContext.d.ts +160 -0
- package/dist/src/turnContext.js +286 -0
- package/dist/src/turnContext.js.map +1 -0
- package/dist/src/turnContextStateCollection.d.ts +29 -0
- package/dist/src/turnContextStateCollection.js +56 -0
- package/dist/src/turnContextStateCollection.js.map +1 -0
- package/package.json +48 -0
- package/src/activityHandler.ts +461 -0
- package/src/agent-client/agentClient.ts +84 -0
- package/src/agent-client/expressApi.ts +59 -0
- package/src/agent-client/index.ts +2 -0
- package/src/app/agentApplication.ts +401 -0
- package/src/app/appRoute.ts +13 -0
- package/src/app/applicationBuilder.ts +42 -0
- package/src/app/applicationOptions.ts +21 -0
- package/src/app/attachmentDownloader.ts +83 -0
- package/src/app/conversationUpdateEvents.ts +8 -0
- package/src/app/index.ts +10 -0
- package/src/app/inputFileDownloader.ts +17 -0
- package/src/app/memory.ts +14 -0
- package/src/app/oauth/authenticationOptions.ts +8 -0
- package/src/app/oauth/webChatOAuthFlowAppStyle.ts +90 -0
- package/src/app/routeHandler.ts +9 -0
- package/src/app/routeSelector.ts +10 -0
- package/src/app/turnEvents.ts +6 -0
- package/src/app/turnState.ts +338 -0
- package/src/app/turnStateEntry.ts +46 -0
- package/src/auth/authConfiguration.ts +68 -0
- package/src/auth/authProvider.ts +19 -0
- package/src/auth/index.ts +4 -0
- package/src/auth/jwt-middleware.ts +99 -0
- package/src/auth/msalTokenProvider.ts +202 -0
- package/src/auth/request.ts +20 -0
- package/src/baseAdapter.ts +174 -0
- package/src/cards/animationCard.ts +38 -0
- package/src/cards/audioCard.ts +38 -0
- package/src/cards/cardFactory.ts +276 -0
- package/src/cards/cardImage.ts +18 -0
- package/src/cards/fact.ts +14 -0
- package/src/cards/heroCard.ts +25 -0
- package/src/cards/index.ts +17 -0
- package/src/cards/mediaUrl.ts +18 -0
- package/src/cards/o365ConnectorCard.ts +37 -0
- package/src/cards/o365ConnectorCardActionBase.ts +24 -0
- package/src/cards/o365ConnectorCardFact.ts +18 -0
- package/src/cards/o365ConnectorCardImage.ts +18 -0
- package/src/cards/o365ConnectorCardSection.ts +60 -0
- package/src/cards/receiptCard.ts +46 -0
- package/src/cards/receiptItem.ts +41 -0
- package/src/cards/signinCard.ts +18 -0
- package/src/cards/taskModuleAction.ts +61 -0
- package/src/cards/thumbnailCard.ts +37 -0
- package/src/cards/thumbnailUrl.ts +18 -0
- package/src/cards/videoCard.ts +62 -0
- package/src/claimsIdentity.ts +47 -0
- package/src/cloudAdapter.ts +431 -0
- package/src/connector-client/attachmentData.ts +26 -0
- package/src/connector-client/attachmentInfo.ts +24 -0
- package/src/connector-client/attachmentView.ts +18 -0
- package/src/connector-client/connectorClient.ts +295 -0
- package/src/connector-client/conversationMembers.ts +20 -0
- package/src/connector-client/conversationParameters.ts +40 -0
- package/src/connector-client/conversationResourceResponse.ts +22 -0
- package/src/connector-client/conversationsResult.ts +20 -0
- package/src/connector-client/index.ts +9 -0
- package/src/connector-client/resourceResponse.ts +14 -0
- package/src/index.ts +31 -0
- package/src/invoke/adaptiveCardAuthentication.ts +13 -0
- package/src/invoke/adaptiveCardInvokeResponse.ts +22 -0
- package/src/invoke/adaptiveCardInvokeValue.ts +25 -0
- package/src/invoke/index.ts +9 -0
- package/src/invoke/invokeException.ts +33 -0
- package/src/invoke/invokeResponse.ts +18 -0
- package/src/invoke/searchInvokeOptions.ts +18 -0
- package/src/invoke/searchInvokeResponse.ts +11 -0
- package/src/invoke/searchInvokeValue.ts +28 -0
- package/src/invoke/tokenExchangeInvokeRequest.ts +22 -0
- package/src/logger.ts +43 -0
- package/src/messageFactory.ts +177 -0
- package/src/middlewareSet.ts +76 -0
- package/src/oauth/index.ts +7 -0
- package/src/oauth/oauthCard.ts +32 -0
- package/src/oauth/signingResource.ts +23 -0
- package/src/oauth/tokenExchangeRequest.ts +20 -0
- package/src/oauth/tokenExchangeResource.ts +20 -0
- package/src/oauth/tokenPostResource.ts +12 -0
- package/src/oauth/userTokenClient.ts +116 -0
- package/src/oauth/webChatOAuthFlow.ts +123 -0
- package/src/state/agentState.ts +142 -0
- package/src/state/agentStatePropertyAccesor.ts +61 -0
- package/src/state/conversationState.ts +42 -0
- package/src/state/index.ts +4 -0
- package/src/state/userState.ts +43 -0
- package/src/statusCodes.ts +20 -0
- package/src/storage/index.ts +2 -0
- package/src/storage/memoryStorage.ts +105 -0
- package/src/storage/storage.ts +52 -0
- package/src/tokenResponseEventName.ts +6 -0
- package/src/transcript/consoleTranscriptLogger.ts +20 -0
- package/src/transcript/index.ts +4 -0
- package/src/transcript/transcriptLogger.ts +45 -0
- package/src/transcript/transcriptLoggerMiddleware.ts +151 -0
- package/src/transcript/transcriptStore.ts +38 -0
- package/src/turnContext.ts +335 -0
- package/src/turnContextStateCollection.ts +69 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */
|
|
2
|
+
import { TurnContext } from './turnContext';
|
|
3
|
+
/**
|
|
4
|
+
* Interface for middleware.
|
|
5
|
+
*/
|
|
6
|
+
export interface Middleware {
|
|
7
|
+
onTurn: (context: TurnContext, next: () => Promise<void>) => Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Type for middleware handler.
|
|
11
|
+
*/
|
|
12
|
+
export type MiddlewareHandler = (context: TurnContext, next: () => Promise<void>) => Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Represents a set of middleware.
|
|
15
|
+
*/
|
|
16
|
+
export declare class MiddlewareSet implements Middleware {
|
|
17
|
+
private readonly middleware;
|
|
18
|
+
/**
|
|
19
|
+
* Initializes a new instance of the MiddlewareSet class.
|
|
20
|
+
* @param middlewares The middleware handlers or middleware objects to use.
|
|
21
|
+
*/
|
|
22
|
+
constructor(...middlewares: Array<MiddlewareHandler | Middleware>);
|
|
23
|
+
/**
|
|
24
|
+
* Handles the turn of the middleware.
|
|
25
|
+
* @param context The turn context.
|
|
26
|
+
* @param next The next function to call.
|
|
27
|
+
* @returns A promise representing the asynchronous operation.
|
|
28
|
+
*/
|
|
29
|
+
onTurn(context: TurnContext, next: () => Promise<void>): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Adds middleware to the set.
|
|
32
|
+
* @param middlewares The middleware handlers or middleware objects to add.
|
|
33
|
+
* @returns The current MiddlewareSet instance.
|
|
34
|
+
*/
|
|
35
|
+
use(...middlewares: Array<MiddlewareHandler | Middleware>): this;
|
|
36
|
+
/**
|
|
37
|
+
* Runs the middleware chain.
|
|
38
|
+
* @param context The turn context.
|
|
39
|
+
* @param next The next function to call.
|
|
40
|
+
* @returns A promise representing the asynchronous operation.
|
|
41
|
+
*/
|
|
42
|
+
run(context: TurnContext, next: () => Promise<void>): Promise<void>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MiddlewareSet = void 0;
|
|
4
|
+
const logger_1 = require("./logger");
|
|
5
|
+
const logger = (0, logger_1.debug)('agents:middleware');
|
|
6
|
+
/**
|
|
7
|
+
* Represents a set of middleware.
|
|
8
|
+
*/
|
|
9
|
+
class MiddlewareSet {
|
|
10
|
+
/**
|
|
11
|
+
* Initializes a new instance of the MiddlewareSet class.
|
|
12
|
+
* @param middlewares The middleware handlers or middleware objects to use.
|
|
13
|
+
*/
|
|
14
|
+
constructor(...middlewares) {
|
|
15
|
+
this.middleware = [];
|
|
16
|
+
this.use(...middlewares);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Handles the turn of the middleware.
|
|
20
|
+
* @param context The turn context.
|
|
21
|
+
* @param next The next function to call.
|
|
22
|
+
* @returns A promise representing the asynchronous operation.
|
|
23
|
+
*/
|
|
24
|
+
async onTurn(context, next) {
|
|
25
|
+
return await this.run(context, next);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Adds middleware to the set.
|
|
29
|
+
* @param middlewares The middleware handlers or middleware objects to add.
|
|
30
|
+
* @returns The current MiddlewareSet instance.
|
|
31
|
+
*/
|
|
32
|
+
use(...middlewares) {
|
|
33
|
+
middlewares.forEach((plugin) => {
|
|
34
|
+
if (typeof plugin === 'function' || (typeof plugin === 'object' && plugin.onTurn)) {
|
|
35
|
+
this.middleware.push(typeof plugin === 'function' ? plugin : async (context, next) => await plugin.onTurn(context, next));
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
throw new Error('MiddlewareSet.use(): invalid plugin type being added.');
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Runs the middleware chain.
|
|
45
|
+
* @param context The turn context.
|
|
46
|
+
* @param next The next function to call.
|
|
47
|
+
* @returns A promise representing the asynchronous operation.
|
|
48
|
+
*/
|
|
49
|
+
async run(context, next) {
|
|
50
|
+
return await this.middleware.reduceRight((nextHandler, currentHandler) => async () => await currentHandler(context, nextHandler), next)().catch(err => {
|
|
51
|
+
logger.error('Error in middleware chain:', err);
|
|
52
|
+
throw err;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.MiddlewareSet = MiddlewareSet;
|
|
57
|
+
//# sourceMappingURL=middlewareSet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middlewareSet.js","sourceRoot":"","sources":["../../src/middlewareSet.ts"],"names":[],"mappings":";;;AAEA,qCAAgC;AAEhC,MAAM,MAAM,GAAG,IAAA,cAAK,EAAC,mBAAmB,CAAC,CAAA;AAczC;;GAEG;AACH,MAAa,aAAa;IAGxB;;;OAGG;IACH,YAAa,GAAG,WAAkD;QANjD,eAAU,GAAwB,EAAE,CAAA;QAOnD,IAAI,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,CAAA;IAC1B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,MAAM,CAAE,OAAoB,EAAE,IAAyB;QAC3D,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IACtC,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAE,GAAG,WAAkD;QACxD,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YAC7B,IAAI,OAAO,MAAM,KAAK,UAAU,IAAI,CAAC,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;gBAClF,IAAI,CAAC,UAAU,CAAC,IAAI,CAClB,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CACpG,CAAA;YACH,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAA;YAC1E,CAAC;QACH,CAAC,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAG,CAAE,OAAoB,EAAE,IAAyB;QACxD,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CACtC,CAAC,WAAW,EAAE,cAAc,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,MAAM,cAAc,CAAC,OAAO,EAAE,WAAW,CAAC,EACzF,IAAI,CACH,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;YACd,MAAM,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAA;YAC/C,MAAM,GAAG,CAAA;QACX,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAtDD,sCAsDC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./oauthCard"), exports);
|
|
18
|
+
__exportStar(require("./signingResource"), exports);
|
|
19
|
+
__exportStar(require("./tokenExchangeResource"), exports);
|
|
20
|
+
__exportStar(require("./tokenPostResource"), exports);
|
|
21
|
+
__exportStar(require("./userTokenClient"), exports);
|
|
22
|
+
__exportStar(require("./webChatOAuthFlow"), exports);
|
|
23
|
+
__exportStar(require("./tokenExchangeRequest"), exports);
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/oauth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA2B;AAC3B,oDAAiC;AACjC,0DAAuC;AACvC,sDAAmC;AACnC,oDAAiC;AACjC,qDAAkC;AAClC,yDAAsC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CardAction } from '@microsoft/agents-activity';
|
|
2
|
+
import { TokenExchangeResource } from './tokenExchangeResource';
|
|
3
|
+
import { TokenPostResource } from './tokenPostResource';
|
|
4
|
+
/**
|
|
5
|
+
* Represents an OAuth card.
|
|
6
|
+
*/
|
|
7
|
+
export interface OAuthCard {
|
|
8
|
+
/**
|
|
9
|
+
* The buttons associated with the OAuth card.
|
|
10
|
+
*/
|
|
11
|
+
buttons: CardAction[];
|
|
12
|
+
/**
|
|
13
|
+
* The connection name for the OAuth card.
|
|
14
|
+
*/
|
|
15
|
+
connectionName: string;
|
|
16
|
+
/**
|
|
17
|
+
* The text content of the OAuth card.
|
|
18
|
+
*/
|
|
19
|
+
text: string;
|
|
20
|
+
/**
|
|
21
|
+
* The token exchange resource for the OAuth card.
|
|
22
|
+
*/
|
|
23
|
+
tokenExchangeResource: TokenExchangeResource;
|
|
24
|
+
/**
|
|
25
|
+
* The token post resource for the OAuth card.
|
|
26
|
+
*/
|
|
27
|
+
tokenPostResource: TokenPostResource;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauthCard.js","sourceRoot":"","sources":["../../../src/oauth/oauthCard.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TokenExchangeResource } from './tokenExchangeResource';
|
|
2
|
+
import { TokenPostResource } from './tokenPostResource';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a resource for signing in.
|
|
5
|
+
*/
|
|
6
|
+
export interface SigningResource {
|
|
7
|
+
/**
|
|
8
|
+
* The link for signing in.
|
|
9
|
+
*/
|
|
10
|
+
singingLink: string;
|
|
11
|
+
/**
|
|
12
|
+
* The resource for token exchange.
|
|
13
|
+
*/
|
|
14
|
+
tokenExchangeResource: TokenExchangeResource;
|
|
15
|
+
/**
|
|
16
|
+
* The resource for token post.
|
|
17
|
+
*/
|
|
18
|
+
tokenPostResource: TokenPostResource;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signingResource.js","sourceRoot":"","sources":["../../../src/oauth/signingResource.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a request for exchanging tokens.
|
|
3
|
+
*/
|
|
4
|
+
export interface TokenExchangeRequest {
|
|
5
|
+
/**
|
|
6
|
+
* The URI for the token exchange request.
|
|
7
|
+
*/
|
|
8
|
+
uri?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The token to be exchanged.
|
|
11
|
+
*/
|
|
12
|
+
token?: string;
|
|
13
|
+
/**
|
|
14
|
+
* The ID associated with the token exchange request.
|
|
15
|
+
*/
|
|
16
|
+
id?: string;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenExchangeRequest.js","sourceRoot":"","sources":["../../../src/oauth/tokenExchangeRequest.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a resource for exchanging tokens.
|
|
3
|
+
*/
|
|
4
|
+
export interface TokenExchangeResource {
|
|
5
|
+
/**
|
|
6
|
+
* The ID of the token exchange resource.
|
|
7
|
+
*/
|
|
8
|
+
id?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The URI of the token exchange resource.
|
|
11
|
+
*/
|
|
12
|
+
uri?: string;
|
|
13
|
+
/**
|
|
14
|
+
* The provider ID for the token exchange resource.
|
|
15
|
+
*/
|
|
16
|
+
providerId?: string;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenExchangeResource.js","sourceRoot":"","sources":["../../../src/oauth/tokenExchangeResource.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenPostResource.js","sourceRoot":"","sources":["../../../src/oauth/tokenPostResource.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { SigningResource } from './signingResource';
|
|
3
|
+
import { Activity } from '@microsoft/agents-activity';
|
|
4
|
+
import { TokenExchangeRequest } from './tokenExchangeRequest';
|
|
5
|
+
/**
|
|
6
|
+
* Client for managing user tokens.
|
|
7
|
+
*/
|
|
8
|
+
export declare class UserTokenClient {
|
|
9
|
+
client: AxiosInstance;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new instance of UserTokenClient.
|
|
12
|
+
* @param token The token to use for authentication.
|
|
13
|
+
*/
|
|
14
|
+
constructor(token: string);
|
|
15
|
+
/**
|
|
16
|
+
* Gets the user token.
|
|
17
|
+
* @param connectionName The connection name.
|
|
18
|
+
* @param channelId The channel ID.
|
|
19
|
+
* @param userId The user ID.
|
|
20
|
+
* @param code The optional code.
|
|
21
|
+
* @returns A promise that resolves to the user token.
|
|
22
|
+
*/
|
|
23
|
+
getUserToken(connectionName: string, channelId: string, userId: string, code?: string): Promise<any>;
|
|
24
|
+
/**
|
|
25
|
+
* Signs the user out.
|
|
26
|
+
* @param userId The user ID.
|
|
27
|
+
* @param connectionName The connection name.
|
|
28
|
+
* @param channelId The channel ID.
|
|
29
|
+
* @returns A promise that resolves when the sign-out operation is complete.
|
|
30
|
+
*/
|
|
31
|
+
signOut(userId: string, connectionName: string, channelId: string): Promise<any>;
|
|
32
|
+
/**
|
|
33
|
+
* Gets the sign-in resource.
|
|
34
|
+
* @param appId The application ID.
|
|
35
|
+
* @param cnxName The connection name.
|
|
36
|
+
* @param activity The activity.
|
|
37
|
+
* @returns A promise that resolves to the signing resource.
|
|
38
|
+
*/
|
|
39
|
+
getSignInResource(appId: string, cnxName: string, activity: Activity): Promise<SigningResource>;
|
|
40
|
+
/**
|
|
41
|
+
* Exchanges the token.
|
|
42
|
+
* @param userId The user ID.
|
|
43
|
+
* @param connectionName The connection name.
|
|
44
|
+
* @param channelId The channel ID.
|
|
45
|
+
* @param tokenExchangeRequest The token exchange request.
|
|
46
|
+
* @returns A promise that resolves to the exchanged token.
|
|
47
|
+
*/
|
|
48
|
+
exchangeTokenAsync(userId: string, connectionName: string, channelId: string, tokenExchangeRequest: TokenExchangeRequest): Promise<any>;
|
|
49
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.UserTokenClient = void 0;
|
|
9
|
+
const axios_1 = __importDefault(require("axios"));
|
|
10
|
+
const logger_1 = require("../logger");
|
|
11
|
+
const logger = (0, logger_1.debug)('agents:userTokenClient');
|
|
12
|
+
/**
|
|
13
|
+
* Client for managing user tokens.
|
|
14
|
+
*/
|
|
15
|
+
class UserTokenClient {
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new instance of UserTokenClient.
|
|
18
|
+
* @param token The token to use for authentication.
|
|
19
|
+
*/
|
|
20
|
+
constructor(token) {
|
|
21
|
+
const baseURL = 'https://api.botframework.com';
|
|
22
|
+
const axiosInstance = axios_1.default.create({
|
|
23
|
+
baseURL,
|
|
24
|
+
headers: {
|
|
25
|
+
Accept: 'application/json'
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
axiosInstance.defaults.headers.common.Authorization = `Bearer ${token}`;
|
|
29
|
+
this.client = axiosInstance;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Gets the user token.
|
|
33
|
+
* @param connectionName The connection name.
|
|
34
|
+
* @param channelId The channel ID.
|
|
35
|
+
* @param userId The user ID.
|
|
36
|
+
* @param code The optional code.
|
|
37
|
+
* @returns A promise that resolves to the user token.
|
|
38
|
+
*/
|
|
39
|
+
async getUserToken(connectionName, channelId, userId, code) {
|
|
40
|
+
var _a;
|
|
41
|
+
try {
|
|
42
|
+
const params = { connectionName, channelId, userId, code };
|
|
43
|
+
const response = await this.client.get('/api/usertoken/GetToken', { params });
|
|
44
|
+
return response.data;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) !== 404) {
|
|
48
|
+
logger.error(error);
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Signs the user out.
|
|
55
|
+
* @param userId The user ID.
|
|
56
|
+
* @param connectionName The connection name.
|
|
57
|
+
* @param channelId The channel ID.
|
|
58
|
+
* @returns A promise that resolves when the sign-out operation is complete.
|
|
59
|
+
*/
|
|
60
|
+
async signOut(userId, connectionName, channelId) {
|
|
61
|
+
try {
|
|
62
|
+
const params = { userId, connectionName, channelId };
|
|
63
|
+
const response = await this.client.delete('/api/usertoken/SignOut', { params });
|
|
64
|
+
return response.data;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
logger.error(error);
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Gets the sign-in resource.
|
|
73
|
+
* @param appId The application ID.
|
|
74
|
+
* @param cnxName The connection name.
|
|
75
|
+
* @param activity The activity.
|
|
76
|
+
* @returns A promise that resolves to the signing resource.
|
|
77
|
+
*/
|
|
78
|
+
async getSignInResource(appId, cnxName, activity) {
|
|
79
|
+
try {
|
|
80
|
+
const tokenExchangeState = {
|
|
81
|
+
ConnectionName: cnxName,
|
|
82
|
+
Conversation: activity.getConversationReference(),
|
|
83
|
+
RelatesTo: activity.RelatesTo,
|
|
84
|
+
MsAppId: appId
|
|
85
|
+
};
|
|
86
|
+
const state = Buffer.from(JSON.stringify(tokenExchangeState)).toString('base64');
|
|
87
|
+
const params = { state };
|
|
88
|
+
const response = await this.client.get('/api/botsignin/GetSignInResource', { params });
|
|
89
|
+
return response.data;
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
logger.error(error);
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Exchanges the token.
|
|
98
|
+
* @param userId The user ID.
|
|
99
|
+
* @param connectionName The connection name.
|
|
100
|
+
* @param channelId The channel ID.
|
|
101
|
+
* @param tokenExchangeRequest The token exchange request.
|
|
102
|
+
* @returns A promise that resolves to the exchanged token.
|
|
103
|
+
*/
|
|
104
|
+
async exchangeTokenAsync(userId, connectionName, channelId, tokenExchangeRequest) {
|
|
105
|
+
try {
|
|
106
|
+
const params = { userId, connectionName, channelId };
|
|
107
|
+
const response = await this.client.post('/api/usertoken/exchange', tokenExchangeRequest, { params });
|
|
108
|
+
return response.data;
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
logger.error(error);
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.UserTokenClient = UserTokenClient;
|
|
117
|
+
//# sourceMappingURL=userTokenClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userTokenClient.js","sourceRoot":"","sources":["../../../src/oauth/userTokenClient.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;;;;AAElC,kDAA4C;AAG5C,sCAAiC;AAGjC,MAAM,MAAM,GAAG,IAAA,cAAK,EAAC,wBAAwB,CAAC,CAAA;AAE9C;;GAEG;AACH,MAAa,eAAe;IAG1B;;;OAGG;IACH,YAAa,KAAa;QACxB,MAAM,OAAO,GAAG,8BAA8B,CAAA;QAC9C,MAAM,aAAa,GAAG,eAAK,CAAC,MAAM,CAAC;YACjC,OAAO;YACP,OAAO,EAAE;gBACP,MAAM,EAAE,kBAAkB;aAC3B;SACF,CAAC,CAAA;QACF,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,aAAa,GAAG,UAAU,KAAK,EAAE,CAAA;QACvE,IAAI,CAAC,MAAM,GAAG,aAAa,CAAA;IAC7B,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,YAAY,CAAE,cAAsB,EAAE,SAAiB,EAAE,MAAc,EAAE,IAAa;;QAC1F,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,CAAA;YAC1D,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,yBAAyB,EAAE,EAAE,MAAM,EAAE,CAAC,CAAA;YAC7E,OAAO,QAAQ,CAAC,IAAI,CAAA;QACtB,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,IAAI,CAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,MAAM,MAAK,GA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C,KAAK,CAAC,KAAK,CAAC,CAAA;YACnB,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,kBAAkB,CAAE,MAAc,EAAE,cAAsB,EAAE,SAAiB,EAAE,oBAA0C;QAC7H,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,CAAA;YACpD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,yBAAyB,EAAE,oBAAoB,EAAE,EAAE,MAAM,EAAE,CAAC,CAAA;YACpG,OAAO,QAAQ,CAAC,IAAI,CAAA;QACtB,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YACnB,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;CACF;AArGD,0CAqGC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { UserTokenClient } from './userTokenClient';
|
|
2
|
+
import { AgentStatePropertyAccessor } from '../state/agentStatePropertyAccesor';
|
|
3
|
+
import { UserState } from '../state/userState';
|
|
4
|
+
import { TurnContext } from '../turnContext';
|
|
5
|
+
declare class FlowState {
|
|
6
|
+
flowStarted: boolean;
|
|
7
|
+
userToken: string;
|
|
8
|
+
flowExpires: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Manages the OAuth flow for Web Chat.
|
|
12
|
+
*/
|
|
13
|
+
export declare class WebChatOAuthFlow {
|
|
14
|
+
userTokenClient?: UserTokenClient;
|
|
15
|
+
state: FlowState | null;
|
|
16
|
+
flowStateAccessor: AgentStatePropertyAccessor<FlowState | null>;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new instance of WebChatOAuthFlow.
|
|
19
|
+
* @param userState The user state.
|
|
20
|
+
*/
|
|
21
|
+
constructor(userState: UserState);
|
|
22
|
+
/**
|
|
23
|
+
* Gets the OAuth token.
|
|
24
|
+
* @param context The turn context.
|
|
25
|
+
* @returns A promise that resolves to the user token.
|
|
26
|
+
*/
|
|
27
|
+
getOAuthToken(context: TurnContext): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Signs the user out.
|
|
30
|
+
* @param context The turn context.
|
|
31
|
+
* @returns A promise that resolves when the sign-out operation is complete.
|
|
32
|
+
*/
|
|
33
|
+
signOut(context: TurnContext): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Gets the user state.
|
|
36
|
+
* @param context The turn context.
|
|
37
|
+
* @returns A promise that resolves to the user state.
|
|
38
|
+
*/
|
|
39
|
+
private getUserState;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.WebChatOAuthFlow = void 0;
|
|
6
|
+
const userTokenClient_1 = require("./userTokenClient");
|
|
7
|
+
const cardFactory_1 = require("../cards/cardFactory");
|
|
8
|
+
const messageFactory_1 = require("../messageFactory");
|
|
9
|
+
const logger_1 = require("../logger");
|
|
10
|
+
const logger = (0, logger_1.debug)('agents:web-chat-oauth-flow');
|
|
11
|
+
class FlowState {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.flowStarted = false;
|
|
14
|
+
this.userToken = '';
|
|
15
|
+
this.flowExpires = 0;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Manages the OAuth flow for Web Chat.
|
|
20
|
+
*/
|
|
21
|
+
class WebChatOAuthFlow {
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new instance of WebChatOAuthFlow.
|
|
24
|
+
* @param userState The user state.
|
|
25
|
+
*/
|
|
26
|
+
constructor(userState) {
|
|
27
|
+
this.state = null;
|
|
28
|
+
this.flowStateAccessor = userState.createProperty('flowState');
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Gets the OAuth token.
|
|
32
|
+
* @param context The turn context.
|
|
33
|
+
* @returns A promise that resolves to the user token.
|
|
34
|
+
*/
|
|
35
|
+
async getOAuthToken(context) {
|
|
36
|
+
var _a, _b, _c;
|
|
37
|
+
this.state = await this.getUserState(context);
|
|
38
|
+
if (this.state.userToken !== '') {
|
|
39
|
+
return this.state.userToken;
|
|
40
|
+
}
|
|
41
|
+
if (((_a = this.state) === null || _a === void 0 ? void 0 : _a.flowExpires) !== 0 && Date.now() > this.state.flowExpires) {
|
|
42
|
+
logger.warn('Sign-in flow expired');
|
|
43
|
+
this.state.flowStarted = false;
|
|
44
|
+
this.state.userToken = '';
|
|
45
|
+
await context.sendActivity(messageFactory_1.MessageFactory.text('Sign-in session expired. Please try again.'));
|
|
46
|
+
}
|
|
47
|
+
let retVal = '';
|
|
48
|
+
const authConfig = context.adapter.authConfig;
|
|
49
|
+
if (authConfig.connectionName === undefined) {
|
|
50
|
+
throw new Error('connectionName is not set in the auth config, review your environment variables');
|
|
51
|
+
}
|
|
52
|
+
const adapter = context.adapter;
|
|
53
|
+
const scope = 'https://api.botframework.com';
|
|
54
|
+
const accessToken = await adapter.authProvider.getAccessToken(authConfig, scope);
|
|
55
|
+
this.userTokenClient = new userTokenClient_1.UserTokenClient(accessToken);
|
|
56
|
+
if (this.state.flowStarted === true) {
|
|
57
|
+
const userToken = await this.userTokenClient.getUserToken(authConfig.connectionName, context.activity.channelId, (_b = context.activity.from) === null || _b === void 0 ? void 0 : _b.id);
|
|
58
|
+
if (userToken !== null) {
|
|
59
|
+
logger.info('Token obtained');
|
|
60
|
+
this.state.userToken = userToken.token;
|
|
61
|
+
this.state.flowStarted = false;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const code = context.activity.text;
|
|
65
|
+
const userToken = await this.userTokenClient.getUserToken(authConfig.connectionName, context.activity.channelId, (_c = context.activity.from) === null || _c === void 0 ? void 0 : _c.id, code);
|
|
66
|
+
if (userToken !== null) {
|
|
67
|
+
logger.info('Token obtained with code');
|
|
68
|
+
this.state.userToken = userToken.token;
|
|
69
|
+
this.state.flowStarted = false;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
logger.error('Sign in failed');
|
|
73
|
+
await context.sendActivity(messageFactory_1.MessageFactory.text('Sign in failed'));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
retVal = this.state.userToken;
|
|
77
|
+
}
|
|
78
|
+
else if (this.state.flowStarted === false) {
|
|
79
|
+
const signingResource = await this.userTokenClient.getSignInResource(authConfig.clientId, authConfig.connectionName, context.activity);
|
|
80
|
+
const oCard = cardFactory_1.CardFactory.oauthCard(authConfig.connectionName, 'Sign in', '', signingResource);
|
|
81
|
+
await context.sendActivity(messageFactory_1.MessageFactory.attachment(oCard));
|
|
82
|
+
this.state.flowStarted = true;
|
|
83
|
+
this.state.flowExpires = Date.now() + 30000;
|
|
84
|
+
logger.info('OAuth flow started');
|
|
85
|
+
}
|
|
86
|
+
this.flowStateAccessor.set(context, this.state);
|
|
87
|
+
return retVal;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Signs the user out.
|
|
91
|
+
* @param context The turn context.
|
|
92
|
+
* @returns A promise that resolves when the sign-out operation is complete.
|
|
93
|
+
*/
|
|
94
|
+
async signOut(context) {
|
|
95
|
+
var _a;
|
|
96
|
+
await this.userTokenClient.signOut((_a = context.activity.from) === null || _a === void 0 ? void 0 : _a.id, context.adapter.authConfig.connectionName, context.activity.channelId);
|
|
97
|
+
this.state.flowStarted = false;
|
|
98
|
+
this.state.userToken = '';
|
|
99
|
+
this.state.flowExpires = 0;
|
|
100
|
+
this.flowStateAccessor.set(context, this.state);
|
|
101
|
+
logger.info('User signed out successfully');
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Gets the user state.
|
|
105
|
+
* @param context The turn context.
|
|
106
|
+
* @returns A promise that resolves to the user state.
|
|
107
|
+
*/
|
|
108
|
+
async getUserState(context) {
|
|
109
|
+
let userProfile = await this.flowStateAccessor.get(context, null);
|
|
110
|
+
if (userProfile === null) {
|
|
111
|
+
userProfile = new FlowState();
|
|
112
|
+
}
|
|
113
|
+
return userProfile;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.WebChatOAuthFlow = WebChatOAuthFlow;
|
|
117
|
+
//# sourceMappingURL=webChatOAuthFlow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webChatOAuthFlow.js","sourceRoot":"","sources":["../../../src/oauth/webChatOAuthFlow.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;AAGlC,uDAAmD;AAEnD,sDAAkD;AAIlD,sDAAkD;AAClD,sCAAiC;AAEjC,MAAM,MAAM,GAAG,IAAA,cAAK,EAAC,4BAA4B,CAAC,CAAA;AAElD,MAAM,SAAS;IAAf;QACS,gBAAW,GAAY,KAAK,CAAA;QAC5B,cAAS,GAAW,EAAE,CAAA;QACtB,gBAAW,GAAW,CAAC,CAAA;IAChC,CAAC;CAAA;AAED;;GAEG;AACH,MAAa,gBAAgB;IAK3B;;;OAGG;IACH,YAAa,SAAoB;QAC/B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;QACjB,IAAI,CAAC,iBAAiB,GAAG,SAAS,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;IAChE,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,aAAa,CAAE,OAAoB;;QAC9C,IAAI,CAAC,KAAK,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;QAC7C,IAAI,IAAI,CAAC,KAAM,CAAC,SAAS,KAAK,EAAE,EAAE,CAAC;YACjC,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAA;QAC7B,CAAC;QACD,IAAI,CAAA,MAAA,IAAI,CAAC,KAAK,0CAAE,WAAW,MAAK,CAAC,IAAI,IAAI,C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