Skip to content

Commit db12ef7

Browse files
Merge pull request #59 from splunk-soar-connectors/tapishj/PAPP-36205
fix: make automatic auth more clear
2 parents 16506b8 + 06fde56 commit db12ef7

10 files changed

+146
-49
lines changed

NOTICE

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,65 @@
1-
Splunk SOAR MS Graph for Office 365
2-
Copyright (c) 2017-2024 Splunk Inc.
1+
Splunk SOAR App: MS Graph for Office 365
2+
Copyright (c) 2017-2025 Splunk Inc.
3+
Third Party Software Attributions:
34

4-
Third-party Software Attributions:
5+
@@@@============================================================================
6+
7+
Library: msal - 1.31.0
8+
Homepage: https://github.com/AzureAD/microsoft-authentication-library-for-python
9+
License: MIT License
10+
License Text:
11+
12+
The MIT License (MIT)
13+
14+
Copyright (c) Microsoft Corporation.
15+
All rights reserved.
16+
17+
This code is licensed under the MIT License.
18+
19+
Permission is hereby granted, free of charge, to any person obtaining a copy
20+
of this software and associated documentation files(the "Software"), to deal
21+
in the Software without restriction, including without limitation the rights
22+
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
23+
copies of the Software, and to permit persons to whom the Software is
24+
furnished to do so, subject to the following conditions :
25+
26+
The above copyright notice and this permission notice shall be included in
27+
all copies or substantial portions of the Software.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
32+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
35+
THE SOFTWARE.
36+
37+
@@@@============================================================================
38+
39+
Library: python-magic - 0.4.18
40+
Homepage: http://github.com/ahupp/python-magic
41+
License: MIT License
42+
License Text:
43+
44+
The MIT License (MIT)
45+
46+
Copyright (c) 2001-2014 Adam Hupp
47+
48+
Permission is hereby granted, free of charge, to any person obtaining a copy
49+
of this software and associated documentation files (the "Software"), to deal
50+
in the Software without restriction, including without limitation the rights
51+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
52+
copies of the Software, and to permit persons to whom the Software is
53+
furnished to do so, subject to the following conditions:
54+
55+
The above copyright notice and this permission notice shall be included in all
56+
copies or substantial portions of the Software.
57+
58+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
61+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
62+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
63+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
64+
SOFTWARE.
565

6-
Library: python-magic
7-
Version: 0.4.18
8-
License: MIT
9-
Copyright 2001-2014 Adam Hupp

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ After making these changes, click **Add permissions** , then select **Grant admi
9292

9393
## Splunk SOAR Graph Asset
9494

95-
When creating an asset for the **MS Graph for Office 365** app, place **Application ID** of the app
96-
created during the app registration on the Azure Portal in the **Application ID** field and place
97-
the client secret generated during the app registration process in the **Application Secret** field.
98-
Then, after filling out the **Tenant** field, click **SAVE** . Both the Application/Client ID and
99-
the Tenant ID can be found in the **Overview** tab on your app's Azure page.
95+
When creating an asset you must choose one of the 3 auth types: **Automatic**, **OAuth**, or **CBA**; and specify your
96+
choice in the **Authentication type to use for connectivity** field. "Automatic" auth means that the app will first try OAuth,
97+
and then if that doesn't work, it will try CBA. For this reason if you choose Automatic auth, the most resilient strategy would be
98+
to specify the parameters required for both OAuth and CBA.
99+
100+
For all three auth types you must fill out the **Application ID** and **Tenant** fields. Both the Application/Client ID and
101+
the Tenant ID can be found in the **Overview** tab on your app's Azure page. After you have these fields filled out click **SAVE**.
100102

101103
After saving, a new field will appear in the **Asset Settings** tab. Take the URL found in the
102104
**POST incoming for MS Graph for Office 365 to this location** field and place it in the **Redirect
@@ -131,7 +133,7 @@ the window. To give this user permission to view assets, follow these steps:
131133

132134
#### Admin User Workflow (OAuth)
133135

134-
- Configure the asset with required details while keeping the **Admin Access Required** as
136+
- Configure the asset with **Tenant ID**, **Application ID** and **Application Secret** while keeping the **Admin Access Required** as
135137
checked.
136138
- While configuring the asset for the first time, keep **Admin Consent Already Provided** as
137139
unchecked.
@@ -154,7 +156,7 @@ the window. To give this user permission to view assets, follow these steps:
154156

155157
#### Non-Admin User Workflow (OAuth)
156158

157-
- Configure the asset with required details while keeping the **Admin Access Required** as
159+
- Configure the asset with **Tenant ID**, **Application ID** and **Application Secret** while keeping the **Admin Access Required** as
158160
unchecked. **Admin Consent Already Provided** config parameter will be ignored in the non-admin
159161
workflow.
160162
- Provide **Access Scope** parameter in the asset configuration. All the actions will get executed
@@ -184,8 +186,8 @@ the window. To give this user permission to view assets, follow these steps:
184186

185187
#### Automatic Authentication Workflow
186188

187-
- Configure the asset with the required details, including either the **Application Secret** or a combination of **Certificate Thumbprint** and **Certificate Private Key (.PEM)**.
188-
- If **Application Secret** exists, it will take priority and follow the OAuth workflow. Otherwise, it will continue with the CBA workflow.
189+
- Configure the asset with both the parameters needed for OAuth and CBA. This means you need to specify either the **Application Secret** or a combination of **Certificate Thumbprint** and **Certificate Private Key (.PEM)**. You may provide all three.
190+
- The OAuth workflow will take priority over the CBA workflow.
189191
- The system doesn’t automatically switch from OAuth to CBA when the **Application Secret** expires. However, if **Admin Access Required** is disabled, **Access Scope** is not specified, and **Admin Consent Already Provided** is enabled, it will switch to CBA upon **Application Secret** expiration.
190192

191193
The app should now be ready to be used.
@@ -309,7 +311,7 @@ VARIABLE | REQUIRED | TYPE | DESCRIPTION
309311
-------- | -------- | ---- | -----------
310312
**tenant** | required | string | Tenant ID (e.g. 1e309abf-db6c-XXXX-a1d2-XXXXXXXXXXXX) |
311313
**client_id** | required | string | Application ID |
312-
**auth_type** | optional | string | Authentication type to use for connectivity |
314+
**auth_type** | required | string | Authentication type to use for connectivity |
313315
**client_secret** | optional | password | Application Secret(required for OAuth) |
314316
**certificate_thumbprint** | optional | password | Certificate Thumbprint (required for CBA) |
315317
**certificate_private_key** | optional | password | Certificate Private Key (.PEM) |

manual_readme_content.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,13 @@ After making these changes, click **Add permissions** , then select **Grant admi
8282

8383
## Splunk SOAR Graph Asset
8484

85-
When creating an asset for the **MS Graph for Office 365** app, place **Application ID** of the app
86-
created during the app registration on the Azure Portal in the **Application ID** field and place
87-
the client secret generated during the app registration process in the **Application Secret** field.
88-
Then, after filling out the **Tenant** field, click **SAVE** . Both the Application/Client ID and
89-
the Tenant ID can be found in the **Overview** tab on your app's Azure page.
85+
When creating an asset you must choose one of the 3 auth types: **Automatic**, **OAuth**, or **CBA**; and specify your
86+
choice in the **Authentication type to use for connectivity** field. "Automatic" auth means that the app will first try OAuth,
87+
and then if that doesn't work, it will try CBA. For this reason if you choose Automatic auth, the most resilient strategy would be
88+
to specify the parameters required for both OAuth and CBA.
89+
90+
For all three auth types you must fill out the **Application ID** and **Tenant** fields. Both the Application/Client ID and
91+
the Tenant ID can be found in the **Overview** tab on your app's Azure page. After you have these fields filled out click **SAVE**.
9092

9193
After saving, a new field will appear in the **Asset Settings** tab. Take the URL found in the
9294
**POST incoming for MS Graph for Office 365 to this location** field and place it in the **Redirect
@@ -121,7 +123,7 @@ the window. To give this user permission to view assets, follow these steps:
121123

122124
#### Admin User Workflow (OAuth)
123125

124-
- Configure the asset with required details while keeping the **Admin Access Required** as
126+
- Configure the asset with **Tenant ID**, **Application ID** and **Application Secret** while keeping the **Admin Access Required** as
125127
checked.
126128
- While configuring the asset for the first time, keep **Admin Consent Already Provided** as
127129
unchecked.
@@ -144,7 +146,7 @@ the window. To give this user permission to view assets, follow these steps:
144146

145147
#### Non-Admin User Workflow (OAuth)
146148

147-
- Configure the asset with required details while keeping the **Admin Access Required** as
149+
- Configure the asset with **Tenant ID**, **Application ID** and **Application Secret** while keeping the **Admin Access Required** as
148150
unchecked. **Admin Consent Already Provided** config parameter will be ignored in the non-admin
149151
workflow.
150152
- Provide **Access Scope** parameter in the asset configuration. All the actions will get executed
@@ -174,8 +176,8 @@ the window. To give this user permission to view assets, follow these steps:
174176

175177
#### Automatic Authentication Workflow
176178

177-
- Configure the asset with the required details, including either the **Application Secret** or a combination of **Certificate Thumbprint** and **Certificate Private Key (.PEM)**.
178-
- If **Application Secret** exists, it will take priority and follow the OAuth workflow. Otherwise, it will continue with the CBA workflow.
179+
- Configure the asset with both the parameters needed for OAuth and CBA. This means you need to specify either the **Application Secret** or a combination of **Certificate Thumbprint** and **Certificate Private Key (.PEM)**. You may provide all three.
180+
- The OAuth workflow will take priority over the CBA workflow.
179181
- The system doesn’t automatically switch from OAuth to CBA when the **Application Secret** expires. However, if **Admin Access Required** is disabled, **Access Scope** is not specified, and **Admin Consent Already Provided** is enabled, it will switch to CBA upon **Application Secret** expiration.
180182

181183
The app should now be ready to be used.

office365.json

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
"auth_type": {
6262
"data_type": "string",
6363
"order": 2,
64+
"required": true,
6465
"description": "Authentication type to use for connectivity",
65-
"default": "Automatic",
6666
"value_list": [
6767
"Automatic",
6868
"OAuth",
@@ -8668,12 +8668,44 @@
86688668
"wheel": [
86698669
{
86708670
"module": "PyJWT",
8671-
"input_file": "wheels/py3/PyJWT-2.10.0-py3-none-any.whl"
8671+
"input_file": "wheels/py3/PyJWT-2.10.1-py3-none-any.whl"
86728672
},
86738673
{
86748674
"module": "cffi",
86758675
"input_file": "wheels/py39/cffi-1.17.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl"
86768676
},
8677+
{
8678+
"module": "cryptography",
8679+
"input_file": "wheels/py3/cryptography-45.0.5-cp37-abi3-manylinux_2_28_x86_64.whl"
8680+
},
8681+
{
8682+
"module": "msal",
8683+
"input_file": "wheels/py3/msal-1.31.0-py3-none-any.whl"
8684+
},
8685+
{
8686+
"module": "pycparser",
8687+
"input_file": "wheels/py3/pycparser-2.22-py3-none-any.whl"
8688+
},
8689+
{
8690+
"module": "python_magic",
8691+
"input_file": "wheels/shared/python_magic-0.4.18-py2.py3-none-any.whl"
8692+
}
8693+
]
8694+
},
8695+
"pip313_dependencies": {
8696+
"wheel": [
8697+
{
8698+
"module": "PyJWT",
8699+
"input_file": "wheels/py3/PyJWT-2.10.1-py3-none-any.whl"
8700+
},
8701+
{
8702+
"module": "cffi",
8703+
"input_file": "wheels/py313/cffi-1.17.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl"
8704+
},
8705+
{
8706+
"module": "cryptography",
8707+
"input_file": "wheels/py3/cryptography-45.0.5-cp311-abi3-manylinux_2_28_x86_64.whl"
8708+
},
86778709
{
86788710
"module": "msal",
86798711
"input_file": "wheels/py3/msal-1.31.0-py3-none-any.whl"

office365_connector.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,11 @@ def _handle_test_connectivity(self, param):
14061406
else:
14071407
self._auth_type = "cba"
14081408
self.save_progress("Failed to obtain consent, switching to Certificate Based Authentication")
1409+
if not (self._thumbprint and self._certificate_private_key):
1410+
return action_result.set_status(
1411+
phantom.APP_ERROR,
1412+
"Tried switching to Certificate Based Authentication, but the necessary CBA configuraiton parameters are not set.",
1413+
)
14091414

14101415
self.save_progress("Getting the token")
14111416
ret_val = self._get_token(action_result)
@@ -3396,9 +3401,6 @@ def initialize(self):
33963401
config = self.get_config()
33973402
self._asset_id = self.get_asset_id()
33983403

3399-
# Load all the asset configuration in global variables
3400-
self._state = self.load_state()
3401-
34023404
self._tenant = config["tenant"]
34033405
self._client_id = config["client_id"]
34043406
self._auth_type = MSGOFFICE365_AUTH_TYPES.get(config.get("auth_type", MSGOFFICE365_AUTH_AUTOMATIC))
@@ -3409,6 +3411,23 @@ def initialize(self):
34093411
self._certificate_private_key = config.get("certificate_private_key")
34103412
self._scope = config.get("scope") if config.get("scope") else None
34113413

3414+
if self._auth_type == "cba":
3415+
# Certificate Based Authentication requires both Certificate Thumbprint and Certificate Private Key
3416+
if not (self._thumbprint and self._certificate_private_key):
3417+
return self.set_status(phantom.APP_ERROR, MSGOFFICE365_CBA_AUTH_ERROR)
3418+
3419+
# Check non-interactive is enabled for CBA auth
3420+
if not self._admin_consent:
3421+
return self.set_status(phantom.APP_ERROR, MSGOFFICE365_CBA_ADMIN_CONSENT_ERROR)
3422+
elif self._auth_type == "oauth":
3423+
# OAuth Authentication requires Client Secret
3424+
if not self._client_secret:
3425+
return self.set_status(phantom.APP_ERROR, MSGOFFICE365_OAUTH_AUTH_ERROR)
3426+
else:
3427+
# Must either supply cba or oauth credentials for automatic auth
3428+
if not self._client_secret and not (self._thumbprint and self._certificate_private_key):
3429+
return self.set_status(phantom.APP_ERROR, MSGOFFICE365_AUTOMATIC_AUTH_ERROR)
3430+
34123431
self._number_of_retries = config.get("retry_count", MSGOFFICE365_DEFAULT_NUMBER_OF_RETRIES)
34133432
ret_val, self._number_of_retries = _validate_integer(
34143433
self, self._number_of_retries, "'Maximum attempts to retry the API call' asset configuration"
@@ -3426,6 +3445,9 @@ def initialize(self):
34263445
if phantom.is_fail(ret_val):
34273446
return self.get_status()
34283447

3448+
# Load all the asset configuration in global variables
3449+
self._state = self.load_state()
3450+
34293451
if not self._admin_access:
34303452
if not self._scope and self._auth_type == "oauth":
34313453
return self.set_status(phantom.APP_ERROR, MSGOFFICE365_NON_ADMIN_SCOPE_ERROR)
@@ -3435,23 +3457,6 @@ def initialize(self):
34353457
else:
34363458
self._access_token = self._state.get("admin_auth", {}).get("access_token", None)
34373459

3438-
if self._auth_type == "cba":
3439-
# Certificate Based Authentication requires both Certificate Thumbprint and Certificate Private Key
3440-
if not (self._thumbprint and self._certificate_private_key):
3441-
return self.set_status(phantom.APP_ERROR, MSGOFFICE365_CBA_AUTH_ERROR)
3442-
3443-
# Check non-interactive is enabled for CBA auth
3444-
if not self._admin_consent:
3445-
return self.set_status(phantom.APP_ERROR, MSGOFFICE365_CBA_ADMIN_CONSENT_ERROR)
3446-
elif self._auth_type == "oauth":
3447-
# OAuth Authentication requires Client Secret
3448-
if not self._client_secret:
3449-
return self.set_status(phantom.APP_ERROR, MSGOFFICE365_OAUTH_AUTH_ERROR)
3450-
else:
3451-
# Must either supply client_secret, or both thumbprint and private key
3452-
if not self._client_secret and not (self._thumbprint and self._certificate_private_key):
3453-
return self.set_status(phantom.APP_ERROR, MSGOFFICE365_AUTOMATIC_AUTH_ERROR)
3454-
34553460
if action_id == "test_connectivity":
34563461
# User is trying to complete the authentication flow, so just return True from here so that test connectivity continues
34573462
return phantom.APP_SUCCESS

release_notes/unreleased.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
**Unreleased**
22

3-
* chore(ci): update pre-commit config
3+
* fix: Improvement to automatic auth by failing Certificate Based Authentication before tokens are deleted if the config parameters for CBA are not provided
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)