Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ disable=print-statement,
too-many-public-methods,
cyclic-import,
too-many-locals,
too-many-function-args
too-many-function-args,
too-many-return-statements

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from msrest import Serializer, Deserializer

from .._configuration import ConnectorClientConfiguration
from msrest.exceptions import HttpOperationError
from .operations_async import AttachmentsOperations
from .operations_async import ConversationsOperations
from .. import models
Expand All @@ -24,14 +23,16 @@ class ConnectorClient(SDKClientAsync):
[Bot Framework Developer Portal](https://dev.botframework.com). The Connector service uses industry-standard REST
and JSON over HTTPS.
Client libraries for this REST API are available. See below for a list.
Many bots will use both the Bot Connector REST API and the associated [Bot State REST API](/en-us/restapi/state). The
Bot State REST API allows a bot to store and retrieve state associated with users and conversations.
Many bots will use both the Bot Connector REST API and the associated [Bot State REST API](/en-us/restapi/state).
The Bot State REST API allows a bot to store and retrieve state associated with users and conversations.
Authentication for both the Bot Connector and Bot State REST APIs is accomplished with JWT Bearer tokens, and is
described in detail in the [Connector Authentication](/en-us/restapi/authentication) document.
# Client Libraries for the Bot Connector REST API
* [Bot Builder for C#](/en-us/csharp/builder/sdkreference/)
* [Bot Builder for Node.js](/en-us/node/builder/overview/)
* Generate your own from the [Connector API Swagger file](https://raw.githubusercontent.com/Microsoft/BotBuilder/master/CSharp/Library/Microsoft.Bot.Connector.Shared/Swagger/ConnectorAPI.json)
* Generate your own from the
[Connector API Swagger file](https://raw.githubusercontent.com/Microsoft/BotBuilder/master/CSharp/Library/
Microsoft.Bot.Connector.Shared/Swagger/ConnectorAPI.json)
© 2016 Microsoft

:ivar config: Configuration for client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
class AttachmentsOperations:
"""AttachmentsOperations async operations.

You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute.
You should not instantiate directly this class, but create a Client instance that will create it for you and attach
it as attribute.

:param client: Client for service requests.
:param config: Configuration of service client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
class ConversationsOperations:
"""ConversationsOperations async operations.

You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute.
You should not instantiate directly this class, but create a Client instance that will create it for you and attach
it as attribute.

:param client: Client for service requests.
:param config: Configuration of service client.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from typing import List


Expand All @@ -9,7 +12,7 @@ def validate(channel_id: str, endorsements: List[str]):
if not channel_id:
return True

if endorsements == None:
if endorsements is None:
raise ValueError("Argument endorsements is null.")

# The Call path to get here is:
Expand All @@ -28,5 +31,5 @@ def validate(channel_id: str, endorsements: List[str]):
# of scope, tokens from WebChat have about 10 endorsements, and
# tokens coming from Teams have about 20.

endorsementPresent = channel_id in endorsements
return endorsementPresent
endorsement_present = channel_id in endorsements
return endorsement_present
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class GovernmentConstants(ABC):
"""
TO CHANNEL FROM BOT: Login URL
"""
TO_CHANNEL_FROM_BOT_LOGIN_URL = "https://login.microsoftonline.us/cab8a31a-1906-4287-a0d8-4eef66b95f6e/oauth2/v2.0/token"
TO_CHANNEL_FROM_BOT_LOGIN_URL = \
"https://login.microsoftonline.us/cab8a31a-1906-4287-a0d8-4eef66b95f6e/oauth2/v2.0/token"

"""
TO CHANNEL FROM BOT: OAuth scope to request
Expand All @@ -36,4 +37,5 @@ class GovernmentConstants(ABC):
"""
TO BOT FROM GOV EMULATOR: OpenID metadata document for tokens coming from MSA
"""
TO_BOT_FROM_EMULATOR_OPEN_ID_METADATA_URL = "https://login.microsoftonline.us/cab8a31a-1906-4287-a0d8-4eef66b95f6e/v2.0/.well-known/openid-configuration"
TO_BOT_FROM_EMULATOR_OPEN_ID_METADATA_URL = \
"https://login.microsoftonline.us/cab8a31a-1906-4287-a0d8-4eef66b95f6e/v2.0/.well-known/openid-configuration"
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import asyncio
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import json
from datetime import datetime, timedelta
import requests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ async def authenticate_request(
channel_service: str = "",
) -> ClaimsIdentity:
"""Authenticates the request and sets the service url in the set of trusted urls.

:param activity: The incoming Activity from the Bot Framework or the Emulator
:type activity: ~botframework.connector.models.Activity
:param auth_header: The Bearer token included as part of the request
:type auth_header: str
:param credentials: The set of valid credentials, such as the Bot Application ID
:param channel_service: String for the channel service
:type credentials: CredentialProvider

:raises Exception:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from urllib.parse import urlparse
from msrest.authentication import BasicTokenAuthentication, Authentication
import requests
import aiohttp
from .constants import Constants

# TODO: Decide to move this to Constants or viceversa (when porting OAuth)
Expand All @@ -11,7 +10,8 @@
"refreshScope": "https://api.botframework.com/.default",
"botConnectorOpenIdMetadata": "https://login.botframework.com/v1/.well-known/openidconfiguration",
"botConnectorIssuer": "https://api.botframework.com",
"emulatorOpenIdMetadata": "https://login.microsoftonline.com/botframework.com/v2.0/.well-known/openid-configuration",
"emulatorOpenIdMetadata":
"https://login.microsoftonline.com/botframework.com/v2.0/.well-known/openid-configuration",
"emulatorAuthV31IssuerV1": "https://sts.windows.net/d6d49420-f39b-4df7-a1dc-d59a935871db/",
"emulatorAuthV31IssuerV2": "https://login.microsoftonline.com/d6d49420-f39b-4df7-a1dc-d59a935871db/v2.0",
"emulatorAuthV32IssuerV1": "https://sts.windows.net/f8cdef31-a31e-4b4a-93e4-5f571e91255a/",
Expand Down Expand Up @@ -63,7 +63,7 @@ def __init__(self, app_id: str, password: str, channel_auth_tenant: str = None):
self.microsoft_app_password = password
tenant = (
channel_auth_tenant
if channel_auth_tenant is not None and len(channel_auth_tenant) > 0
if channel_auth_tenant
else Constants.DEFAULT_CHANNEL_AUTH_TENANT
)
self.oauth_endpoint = (
Expand All @@ -73,7 +73,7 @@ def __init__(self, app_id: str, password: str, channel_auth_tenant: str = None):
)
self.token_cache_key = app_id + "-cache"

def signed_session(self) -> requests.Session:
def signed_session(self) -> requests.Session: # pylint: disable=arguments-differ
"""
Gets the signed session.
:returns: Signed requests.Session object
Expand Down Expand Up @@ -113,8 +113,7 @@ def get_access_token(self, force_refresh: bool = False) -> str:
oauth_token = self.refresh_token()
MicrosoftAppCredentials.cache.setdefault(self.token_cache_key, oauth_token)
return oauth_token.access_token
else:
return ""
return ""

def refresh_token(self) -> _OAuthResponse:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from msrest import Serializer, Deserializer

from ._configuration import ConnectorClientConfiguration
from msrest.exceptions import HttpOperationError
from .operations import AttachmentsOperations
from .operations import ConversationsOperations
from . import models
Expand All @@ -24,14 +23,16 @@ class ConnectorClient(SDKClient):
[Bot Framework Developer Portal](https://dev.botframework.com). The Connector service uses industry-standard REST
and JSON over HTTPS.
Client libraries for this REST API are available. See below for a list.
Many bots will use both the Bot Connector REST API and the associated [Bot State REST API](/en-us/restapi/state). The
Bot State REST API allows a bot to store and retrieve state associated with users and conversations.
Many bots will use both the Bot Connector REST API and the associated [Bot State REST API](/en-us/restapi/state).
The Bot State REST API allows a bot to store and retrieve state associated with users and conversations.
Authentication for both the Bot Connector and Bot State REST APIs is accomplished with JWT Bearer tokens, and is
described in detail in the [Connector Authentication](/en-us/restapi/authentication) document.
# Client Libraries for the Bot Connector REST API
* [Bot Builder for C#](/en-us/csharp/builder/sdkreference/)
* [Bot Builder for Node.js](/en-us/node/builder/overview/)
* Generate your own from the [Connector API Swagger file](https://raw.githubusercontent.com/Microsoft/BotBuilder/master/CSharp/Library/Microsoft.Bot.Connector.Shared/Swagger/ConnectorAPI.json)
* Generate your own from the
[Connector API Swagger file](https://raw.githubusercontent.com/Microsoft/BotBuilder/master/CSharp/Library
/Microsoft.Bot.Connector.Shared/Swagger/ConnectorAPI.json)
© 2016 Microsoft

:ivar config: Configuration for client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async def emulate_oauth_cards(

if res.status_code == 200:
return True
else:
raise Exception(
f"EmulateOAuthCards failed with status code: { res.status_code }"
)

raise Exception(
f"EmulateOAuthCards failed with status code: { res.status_code }"
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
from .. import models


class AttachmentsOperations(object):
class AttachmentsOperations:
"""AttachmentsOperations operations.

You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute.
You should not instantiate directly this class, but create a Client instance that will create it for you and attach
it as attribute.

:param client: Client for service requests.
:param config: Configuration of service client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
from .. import models


class ConversationsOperations(object):
class ConversationsOperations:
"""ConversationsOperations operations.

You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute.
You should not instantiate directly this class, but create a Client instance that will create it for you and attach
it as attribute.

:param client: Client for service requests.
:param config: Configuration of service client.
Expand Down Expand Up @@ -532,7 +533,7 @@ def reply_to_activity(
"url": "/v3/conversations/{conversationId}/activities/{activityId}"
}

def delete_activity(
def delete_activity( # pylint: disable=inconsistent-return-statements
self,
conversation_id,
activity_id,
Expand Down Expand Up @@ -744,7 +745,7 @@ def get_conversation_paged_members(
"url": "/v3/conversations/{conversationId}/pagedmembers"
}

def delete_conversation_member(
def delete_conversation_member( # pylint: disable=inconsistent-return-statements
self,
conversation_id,
member_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from msrest import Serializer, Deserializer

from ._configuration import TokenApiClientConfiguration
from msrest.exceptions import HttpOperationError
from .operations import BotSignInOperations
from .operations import UserTokenOperations
from . import models
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from msrest import Serializer, Deserializer

from .._configuration import TokenApiClientConfiguration
from msrest.exceptions import HttpOperationError
from .operations_async import BotSignInOperations
from .operations_async import UserTokenOperations
from .. import models
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
class BotSignInOperations:
"""BotSignInOperations async operations.

You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute.
You should not instantiate directly this class, but create a Client instance that will create it for you and attach
it as attribute.

:param client: Client for service requests.
:param config: Configuration of service client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
class UserTokenOperations:
"""UserTokenOperations async operations.

You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute.
You should not instantiate directly this class, but create a Client instance that will create it for you and attach
it as attribute.

:param client: Client for service requests.
:param config: Configuration of service client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
from .. import models


class BotSignInOperations(object):
class BotSignInOperations:
"""BotSignInOperations operations.

You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute.
You should not instantiate directly this class, but create a Client instance that will create it for you and attach
it as attribute.

:param client: Client for service requests.
:param config: Configuration of service client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
from .. import models


class UserTokenOperations(object):
class UserTokenOperations:
"""UserTokenOperations operations.

You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute.
You should not instantiate directly this class, but create a Client instance that will create it for you and attach
it as attribute.

:param client: Client for service requests.
:param config: Configuration of service client.
Expand Down
9 changes: 6 additions & 3 deletions libraries/botframework-connector/tests/authentication_stub.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from msrest.authentication import BasicTokenAuthentication, Authentication


class MicrosoftTokenAuthenticationStub(Authentication):
def __init__(self, access_token):
self.access_token = access_token

def signed_session(self):
basicAuthentication = BasicTokenAuthentication(
def signed_session(self, session=None):
basic_authentication = BasicTokenAuthentication(
{"access_token": self.access_token}
)
return basicAuthentication.signed_session()
return session or basic_authentication.signed_session()
15 changes: 9 additions & 6 deletions libraries/botframework-connector/tests/test_attachments.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import os
import base64
import pytest
import asyncio
import pytest
from azure_devtools.scenario_tests import ReplayableTest

import msrest
from botbuilder.schema import *
from botbuilder.schema import AttachmentData, ErrorResponseException
from botframework.connector import ConnectorClient
from botframework.connector.auth import MicrosoftAppCredentials

Expand Down Expand Up @@ -43,8 +46,8 @@ def read_base64(path_to_file):
return encoded_string


loop = asyncio.get_event_loop()
auth_token = loop.run_until_complete(get_auth_token())
LOOP = asyncio.get_event_loop()
AUTH_TOKEN = LOOP.run_until_complete(get_auth_token())


class AttachmentsTest(ReplayableTest):
Expand All @@ -53,7 +56,7 @@ def __init__(self, method_name):

@property
def credentials(self):
return MicrosoftTokenAuthenticationStub(auth_token)
return MicrosoftTokenAuthenticationStub(AUTH_TOKEN)

def test_attachments_upload_and_get_attachment(self):
attachment = AttachmentData(
Expand Down Expand Up @@ -124,7 +127,7 @@ def test_attachments_get_attachment_view_with_invalid_view_id_fails(self):
CONVERSATION_ID, attachment
)
attachment_id = response.id
attachment_view = connector.attachments.get_attachment(
connector.attachments.get_attachment(
attachment_id, "invalid"
)

Expand Down
Loading