|
12 | 12 | from .groups import Groups |
13 | 13 | from .metrics.metrics import Metrics |
14 | 14 | from .oauth.oauth import OAuth |
15 | | -from .oauth.types import OAuthTokenType |
| 15 | +from .oauth.types import OAuthIntegrationType, OAuthTokenType |
16 | 16 | from .resources import _PaginatedResourceSequence, _ResourceSequence |
17 | 17 | from .sessions import Session |
18 | 18 | from .system import System |
@@ -198,6 +198,10 @@ def with_user_session_token( |
198 | 198 | ---------- |
199 | 199 | token : str |
200 | 200 | The user session token. |
| 201 | + audience : str, optional |
| 202 | + The audience for the token exchange. This is the integration GUID of the Connect API integration |
| 203 | + that is associate with the content. If not provided when there are multiple integrations, the |
| 204 | + function will attempt to determine the audience from the current content associations. |
201 | 205 |
|
202 | 206 | Returns |
203 | 207 | ------- |
@@ -260,6 +264,18 @@ def user_profile(): |
260 | 264 | if token is None or token == "": |
261 | 265 | raise ValueError("token must be set to non-empty string.") |
262 | 266 |
|
| 267 | + # If the audience is not provided and there are multiple associations, |
| 268 | + # we will try to find the Connect API integration GUID from the content resource. |
| 269 | + current_content_associations = self.content.get().oauth.associations.find() |
| 270 | + if audience is None and len(current_content_associations) > 1: |
| 271 | + connect_api_integration_guids = [ |
| 272 | + a["oauth_integration_guid"] |
| 273 | + for a in current_content_associations |
| 274 | + if a.get("oauth_integration_template") == OAuthIntegrationType.CONNECT |
| 275 | + ] |
| 276 | + if len(connect_api_integration_guids) == 1: |
| 277 | + audience = connect_api_integration_guids[0] |
| 278 | + |
263 | 279 | visitor_credentials = self.oauth.get_credentials( |
264 | 280 | token, |
265 | 281 | requested_token_type=OAuthTokenType.API_KEY, |
|
0 commit comments