diff --git a/Packs/MicrosoftGraphTeams/Integrations/MicrosoftGraphTeams/MicrosoftGraphTeams.py b/Packs/MicrosoftGraphTeams/Integrations/MicrosoftGraphTeams/MicrosoftGraphTeams.py index 2ac184f361ca..06a54b16a14f 100644 --- a/Packs/MicrosoftGraphTeams/Integrations/MicrosoftGraphTeams/MicrosoftGraphTeams.py +++ b/Packs/MicrosoftGraphTeams/Integrations/MicrosoftGraphTeams/MicrosoftGraphTeams.py @@ -1,6 +1,5 @@ import demistomock as demisto # noqa: F401 from CommonServerPython import * # noqa: F401 -from typing import Optional, Union ''' IMPORTS ''' @@ -19,8 +18,8 @@ class MsGraphClient: def __init__(self, tenant_id, auth_id, enc_key, app_name, base_url, verify, proxy, self_deployed, - redirect_uri, auth_code, handle_error, certificate_thumbprint: Optional[str] = None, - private_key: Optional[str] = None, delegated_user: Optional[str] = None + redirect_uri, auth_code, handle_error, certificate_thumbprint: str | None = None, + private_key: str | None = None, delegated_user: str | None = None ): grant_type = AUTHORIZATION_CODE if auth_code and redirect_uri else CLIENT_CREDENTIALS @@ -29,7 +28,7 @@ def __init__(self, tenant_id, auth_id, enc_key, app_name, base_url, verify, prox base_url=base_url, verify=verify, proxy=proxy, self_deployed=self_deployed, redirect_uri=redirect_uri, auth_code=auth_code, grant_type=grant_type, resource=resource, certificate_thumbprint=certificate_thumbprint, - private_key=private_key) + private_key=private_key, command_prefix='msgraph-teams') self.handle_error = handle_error self.delegated_user = delegated_user @@ -101,7 +100,7 @@ def pages_puller(self, response: dict, page_count: int = 100) -> list: list: list of all pages """ responses = [response] - for i in range(page_count - 1): + for _i in range(page_count - 1): next_link = response.get('@odata.nextLink') if next_link: response = self.ms_client.http_request('GET', full_url=next_link, url_suffix=None) @@ -110,7 +109,7 @@ def pages_puller(self, response: dict, page_count: int = 100) -> list: return responses return responses - def list_chats(self, user_id: str = None, odata: str = None, limit: str = '20') -> Union[dict, list]: + def list_chats(self, user_id: str = None, odata: str = None, limit: str = '20') -> dict | list: """Returning all chats from given user Args: @@ -187,7 +186,7 @@ def update_chat(self, chat_id: str, subject: str) -> dict: } return self.ms_client.http_request(method='PATCH', url_suffix=suffix, json_data=json_data) - def list_members(self, chat_id: str, user_id: str = None) -> Union[dict, list]: + def list_members(self, chat_id: str, user_id: str = None) -> dict | list: """Returning all members from given chat Args: @@ -227,7 +226,7 @@ def add_member(self, chat_id: str, user_id: str, share_history: bool) -> bool: return True - def list_messages(self, chat_id: str, user_id: str = None, limit: str = '50') -> Union[dict, list]: + def list_messages(self, chat_id: str, user_id: str = None, limit: str = '50') -> dict | list: """Returning all mails from given user Args: @@ -270,7 +269,7 @@ def send_message(self, chat_id: str, body: str) -> dict: ''' HELPER FUNCTIONS ''' -def build_chat_object(raw_response: Union[dict, list], user_id: str = None): +def build_chat_object(raw_response: dict | list, user_id: str = None): """Building chat entry context Getting a list from build_chat_object @@ -307,7 +306,7 @@ def build_chat(given_chat: dict) -> dict: entry['UserID'] = user_id return entry - chat_list = list() + chat_list = [] if isinstance(raw_response, list): # response from list_emails_command for page in raw_response: # raw_response is a list containing multiple pages or one page @@ -326,7 +325,7 @@ def build_chat(given_chat: dict) -> dict: return chat_list -def build_member_object(raw_response: Union[dict, list], chat_id: str) -> Union[dict, list]: +def build_member_object(raw_response: dict | list, chat_id: str) -> dict | list: """Building member entry context Getting a list from build_member_object @@ -361,7 +360,7 @@ def build_member(given_member: dict) -> dict: entry['ChatID'] = chat_id return entry - member_list = list() + member_list = [] if isinstance(raw_response, list): # response from list_emails_command for page in raw_response: # raw_response is a list containing multiple pages or one page @@ -380,7 +379,7 @@ def build_member(given_member: dict) -> dict: return member_list -def build_message_object(raw_response: Union[dict, list], chat_id: str) -> Union[dict, list]: +def build_message_object(raw_response: dict | list, chat_id: str) -> dict | list: """Building message entry context Getting a list from build_message_object @@ -418,7 +417,7 @@ def build_message(given_message: dict) -> dict: entry['ChatID'] = chat_id return entry - message_list = list() + message_list = [] if isinstance(raw_response, list): # response from list_emails_command for page in raw_response: # raw_response is a list containing multiple pages or one page @@ -457,6 +456,7 @@ def test_function(client, _): "Please enable the integration and run the !msgraph-teams-test command in order to test it") client.ms_client.http_request(method='GET', url_suffix='chats') + return_results(CommandResults(readable_output='✅ Success!')) return response, None, None @@ -683,9 +683,6 @@ def main(): if not self_deployed and not enc_key: raise DemistoException('Key must be provided. For further information see ' 'https://xsoar.pan.dev/docs/reference/articles/microsoft-integrations---authentication') - if self_deployed and ((auth_code and not redirect_uri) or (not auth_code and redirect_uri)): - raise DemistoException('Please provide both Application redirect URI and Authorization code ' - 'for Authorization Code flow, or None for the Client Credentials flow') elif not enc_key and not (certificate_thumbprint and private_key): raise DemistoException('Key or Certificate Thumbprint and Private Key must be provided.') @@ -715,7 +712,12 @@ def main(): auth_code=auth_code, handle_error=handle_error, certificate_thumbprint=certificate_thumbprint, private_key=private_key, delegated_user=delegated_user) - run_command(commands, command, client, demisto.args(), tries) + if command == 'msgraph-teams-generate-login-url': + return_results(generate_login_url(client.ms_client)) + elif command == 'msgraph-teams-auth-reset': + return_results(reset_auth()) + else: + run_command(commands, command, client, demisto.args(), tries) except Exception as e: return_error(str(e)) diff --git a/Packs/MicrosoftGraphTeams/Integrations/MicrosoftGraphTeams/MicrosoftGraphTeams.yml b/Packs/MicrosoftGraphTeams/Integrations/MicrosoftGraphTeams/MicrosoftGraphTeams.yml index 60776b90a694..1f45071783af 100644 --- a/Packs/MicrosoftGraphTeams/Integrations/MicrosoftGraphTeams/MicrosoftGraphTeams.yml +++ b/Packs/MicrosoftGraphTeams/Integrations/MicrosoftGraphTeams/MicrosoftGraphTeams.yml @@ -297,7 +297,14 @@ script: - arguments: [] description: Tests connectivity to Microsoft Graph Teams. name: msgraph-teams-test - dockerimage: demisto/crypto:1.0.0.66562 + - description: Generate the login url used for Authorization code flow. + name: msgraph-teams-generate-login-url + arguments: [] + - description: Run this command if for some reason you need to rerun the authentication process. + execution: false + name: msgraph-teams-auth-reset + arguments: [] + dockerimage: demisto/crypto:1.0.0.68914 script: '' subtype: python3 type: python diff --git a/Packs/MicrosoftGraphTeams/Integrations/MicrosoftGraphTeams/README.md b/Packs/MicrosoftGraphTeams/Integrations/MicrosoftGraphTeams/README.md index ee4e2b66863d..17cac8e203ca 100644 --- a/Packs/MicrosoftGraphTeams/Integrations/MicrosoftGraphTeams/README.md +++ b/Packs/MicrosoftGraphTeams/Integrations/MicrosoftGraphTeams/README.md @@ -1,4 +1,5 @@ Microsoft Graph lets your app get authorized access to a user's Teams app in a personal or organization account. + ## Configure O365 Teams (Using Graph API) on Cortex XSOAR 1. Navigate to **Settings** > **Integrations** > **Servers & Services**. @@ -25,6 +26,7 @@ Microsoft Graph lets your app get authorized access to a user's Teams app in a p #### Required Permissions + Chat.Create - Delegated Chat.Read - Delegated Chat.ReadBasic - Delegated @@ -35,9 +37,12 @@ ChatMessage.Read - Delegated ChatMessage.Send - Delegated ## Commands + You can execute these commands from the Cortex XSOAR CLI, as part of an automation, or in a playbook. After you successfully execute a command, a DBot message appears in the War Room with the command details. + ### msgraph-teams-list-chats + *** Retrieve the list of chats that the user is part of. @@ -45,6 +50,7 @@ Retrieve the list of chats that the user is part of. #### Base Command `msgraph-teams-list-chats` + #### Input | **Argument Name** | **Description** | **Required** | @@ -66,6 +72,7 @@ Retrieve the list of chats that the user is part of. | MSGraphTeamsChat.Type | String | The type of chat. | ### msgraph-teams-create-chat + *** Create a new chat. @@ -73,6 +80,7 @@ Create a new chat. #### Base Command `msgraph-teams-create-chat` + #### Input | **Argument Name** | **Description** | **Required** | @@ -95,6 +103,7 @@ Create a new chat. | MSGraphTeamsChat.Type | String | The type of chat. | ### msgraph-teams-get-chat + *** Retrieve a single chat (without its messages). @@ -102,6 +111,7 @@ Retrieve a single chat (without its messages). #### Base Command `msgraph-teams-get-chat` + #### Input | **Argument Name** | **Description** | **Required** | @@ -122,6 +132,7 @@ Retrieve a single chat (without its messages). | MSGraphTeamsChat.Type | String | The type of chat. | ### msgraph-teams-update-chat + *** Update the properties of a chat object. @@ -129,6 +140,7 @@ Update the properties of a chat object. #### Base Command `msgraph-teams-update-chat` + #### Input | **Argument Name** | **Description** | **Required** | @@ -149,6 +161,7 @@ Update the properties of a chat object. | MSGraphTeamsChat.Type | String | The type of chat. | ### msgraph-teams-list-members + *** List all conversation members in a chat. @@ -156,6 +169,7 @@ List all conversation members in a chat. #### Base Command `msgraph-teams-list-members` + #### Input | **Argument Name** | **Description** | **Required** | @@ -174,6 +188,7 @@ List all conversation members in a chat. | MSGraphTeamsChatMember.ChatID | unknown | The ID of the chat. | ### msgraph-teams-add-member + *** Add a conversationMember to a chat. @@ -181,6 +196,7 @@ Add a conversationMember to a chat. #### Base Command `msgraph-teams-add-member` + #### Input | **Argument Name** | **Description** | **Required** | @@ -193,7 +209,9 @@ Add a conversationMember to a chat. #### Context Output There is no context output for this command. + ### msgraph-teams-list-messages + *** Retrieve the list of messages in a chat. @@ -201,6 +219,7 @@ Retrieve the list of messages in a chat. #### Base Command `msgraph-teams-list-messages` + #### Input | **Argument Name** | **Description** | **Required** | @@ -222,6 +241,7 @@ Retrieve the list of messages in a chat. | MSGraphTeamsChatMessage.Body | htmlBody | HTML representation of the content of the chat message. Representation is specified by the contentType inside the body. | ### msgraph-teams-send-message + *** Send a new message in a chat. @@ -229,6 +249,7 @@ Send a new message in a chat. #### Base Command `msgraph-teams-send-message` + #### Input | **Argument Name** | **Description** | **Required** | @@ -249,6 +270,7 @@ Send a new message in a chat. | MSGraphTeamsChatMessage.Body | htmlBody | HTML representation of the content of the chat message. Representation is specified by the contentType inside the body. | ### msgraph-teams-test + *** Tests connectivity to Microsoft Graph Teams. @@ -256,12 +278,49 @@ Tests connectivity to Microsoft Graph Teams. #### Base Command `msgraph-teams-test` + +#### Input + +| **Argument Name** | **Description** | **Required** | +| --- | --- | --- | + + +#### Context Output + +There is no context output for this command. + +### msgraph-teams-auth-reset + +*** +Run this command if for some reason you need to rerun the authentication process. + +#### Base Command + +`msgraph-teams-auth-reset` + #### Input | **Argument Name** | **Description** | **Required** | | --- | --- | --- | +#### Context Output + +There is no context output for this command. + +### msgraph-teams-generate-login-url + +*** +Generate the login url used for Authorization code flow. + +#### Base Command + +`msgraph-teams-generate-login-url` + +#### Input + +| **Argument Name** | **Description** | **Required** | +| --- | --- | --- | #### Context Output -There is no context output for this command. \ No newline at end of file +There is no context output for this command. diff --git a/Packs/MicrosoftGraphTeams/ReleaseNotes/1_0_10.md b/Packs/MicrosoftGraphTeams/ReleaseNotes/1_0_10.md new file mode 100644 index 000000000000..fa1d0b836e5e --- /dev/null +++ b/Packs/MicrosoftGraphTeams/ReleaseNotes/1_0_10.md @@ -0,0 +1,6 @@ + +#### Integrations + +##### O365 Teams (Using Graph API) +- Updated the Docker image to: *demisto/crypto:1.0.0.68914*. +- Added support for the ***msgraph-teams-auth-reset*** and ***msgraph-teams-generate-login-url*** commands. diff --git a/Packs/MicrosoftGraphTeams/pack_metadata.json b/Packs/MicrosoftGraphTeams/pack_metadata.json index 6762ea6d27c4..93a82af16c6b 100644 --- a/Packs/MicrosoftGraphTeams/pack_metadata.json +++ b/Packs/MicrosoftGraphTeams/pack_metadata.json @@ -2,7 +2,7 @@ "name": "MicrosoftGraphTeams", "description": "O365 Teams (Using Graph API) gives you authorized access to a user’s Teams enabling you to facilitate communication through teams as that user, or read conversations and/or messages of that user.", "support": "community", - "currentVersion": "1.0.9", + "currentVersion": "1.0.10", "author": "Joachim Bockland", "url": "", "email": "",