Title: Credentials subject and Domain-wide delegation access issue for BetaAnalyticsDataClient · Issue #341 · googleapis/python-analytics-data · GitHub
Open Graph Title: Credentials subject and Domain-wide delegation access issue for BetaAnalyticsDataClient · Issue #341 · googleapis/python-analytics-data
X Title: Credentials subject and Domain-wide delegation access issue for BetaAnalyticsDataClient · Issue #341 · googleapis/python-analytics-data
Description: Environment details OS type and version: Linux-5.4.0-1094-aws-x86_64-with-glibc2.17 Python version: Python 3.8.12 pip version: pip 21.2.4 google-analytics-data version: Version: 0.16.1 Steps to reproduce Using quickstart.py code supplied...
Open Graph Description: Environment details OS type and version: Linux-5.4.0-1094-aws-x86_64-with-glibc2.17 Python version: Python 3.8.12 pip version: pip 21.2.4 google-analytics-data version: Version: 0.16.1 Steps to rep...
X Description: Environment details OS type and version: Linux-5.4.0-1094-aws-x86_64-with-glibc2.17 Python version: Python 3.8.12 pip version: pip 21.2.4 google-analytics-data version: Version: 0.16.1 Steps to rep...
Opengraph URL: https://github.com/googleapis/python-analytics-data/issues/341
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Credentials subject and Domain-wide delegation access issue for BetaAnalyticsDataClient","articleBody":"#### Environment details\r\n\r\n - OS type and version: Linux-5.4.0-1094-aws-x86_64-with-glibc2.17\r\n - Python version: Python 3.8.12\r\n - pip version: pip 21.2.4\r\n - `google-analytics-data` version: Version: 0.16.1\r\n\r\n#### Steps to reproduce\r\n\r\n 1. Using quickstart.py code supplied in this repo;\r\n 2. Using the domain-wide delegation scopes below in Workspace Admin;\r\n 3. Oauth subject email has Administrator access to property;\r\n 4. API access granted for GCP project;\r\n 5. Using service account that currently operates normally for GA and GSC using subject delegation.\r\n\r\n#### Domain-wide Delegation Scopes\r\n```\r\nhttps://www.googleapis.com/auth/webmasters.readonly\r\nhttps://www.googleapis.com/auth/analytics.readonly\r\nhttps://www.googleapis.com/auth/analytics\r\nopenid\r\n```\r\n\r\n#### Code example\r\n\r\n```python\r\nfrom google.analytics.data_v1beta import BetaAnalyticsDataClient\r\nfrom google.oauth2 import service_account\r\nfrom google.analytics.data_v1beta.types import (\r\n DateRange,\r\n Dimension,\r\n Metric,\r\n RunReportRequest,\r\n)\r\n\r\n\r\nSERVICE_ACCOUNT_CREDENTIALS = \"credentials/path-to-service-account-json.json\"\r\nSERVICE_ACCOUNT_SUBJECT = \"user@domain.com\"\r\n\r\ndef sample_run_report(property_id=\"\u003cproperty-id>\"):\r\n \"\"\"Runs a simple report on a Google Analytics 4 property.\"\"\"\r\n # TODO(developer): Uncomment this variable and replace with your\r\n # Google Analytics 4 property ID before running the sample.\r\n # property_id = \"YOUR-GA4-PROPERTY-ID\"\r\n\r\n # [START analyticsdata_json_credentials_initialize]\r\n # TODO(developer): Uncomment this variable and replace with a valid path to\r\n # the credentials.json file for your service account downloaded from the\r\n # Cloud Console.\r\n # credentials_json_path = \"/path/to/credentials.json\"\r\n\r\n # Explicitly use service account credentials by specifying\r\n # the private key file.\r\n credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_CREDENTIALS, subject=SERVICE_ACCOUNT_SUBJECT)\r\n client = BetaAnalyticsDataClient(credentials=credentials)\r\n \r\n # [END analyticsdata_json_credentials_initialize]\r\n\r\n # [START analyticsdata_json_credentials_run_report]\r\n request = RunReportRequest(\r\n property=f\"properties/{property_id}\",\r\n dimensions=[Dimension(name=\"city\")],\r\n metrics=[Metric(name=\"activeUsers\")],\r\n date_ranges=[DateRange(start_date=\"2020-03-31\", end_date=\"today\")],\r\n )\r\n response = client.run_report(request)\r\n # [END analyticsdata_json_credentials_run_report]\r\n\r\n print(\"Report result:\")\r\n for row in response.rows:\r\n print(row.dimension_values[0].value, row.metric_values[0].value)\r\n\r\n\r\nsample_run_report(property_id=\"XXXXXXXXXX\")\r\n\r\n```\r\n\r\n#### Stack trace\r\n```\r\n_InactiveRpcError Traceback (most recent call last)\r\n/opt/tljh/user/lib/python3.8/site-packages/google/api_core/grpc_helpers.py in error_remapped_callable(*args, **kwargs)\r\n 64 try:\r\n---> 65 return callable_(*args, **kwargs)\r\n 66 except grpc.RpcError as exc:\r\n\r\n/opt/tljh/user/lib/python3.8/site-packages/grpc/_channel.py in __call__(self, request, timeout, metadata, credentials, wait_for_ready, compression)\r\n 945 wait_for_ready, compression)\r\n--> 946 return _end_unary_response_blocking(state, call, False, None)\r\n 947 \r\n\r\n/opt/tljh/user/lib/python3.8/site-packages/grpc/_channel.py in _end_unary_response_blocking(state, call, with_call, deadline)\r\n 848 else:\r\n--> 849 raise _InactiveRpcError(state)\r\n 850 \r\n\r\n_InactiveRpcError: \u003c_InactiveRpcError of RPC that terminated with:\r\n\tstatus = StatusCode.PERMISSION_DENIED\r\n\tdetails = \"User does not have sufficient permissions for this property. To learn more about Property ID, see https://developers.google.com/analytics/devguides/reporting/data/v1/property-id.\"\r\n\tdebug_error_string = \"UNKNOWN:Error received from peer ipv4:172.253.63.95:443 {created_time:\"2023-02-09T13:29:52.563206159+00:00\", grpc_status:7, grpc_message:\"User does not have sufficient permissions for this property. To learn more about Property ID, see https://developers.google.com/analytics/devguides/reporting/data/v1/property-id.\"}\"\r\n>\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nPermissionDenied Traceback (most recent call last)\r\n/tmp/ipykernel_30595/3858193892.py in \u003cmodule>\r\n 46 \r\n 47 \r\n---> 48 sample_run_report(property_id=\"281603923\")\r\n\r\n/tmp/ipykernel_30595/3858193892.py in sample_run_report(property_id)\r\n 38 date_ranges=[DateRange(start_date=\"2020-03-31\", end_date=\"today\")],\r\n 39 )\r\n---> 40 response = client.run_report(request)\r\n 41 # [END analyticsdata_json_credentials_run_report]\r\n 42 \r\n\r\n/opt/tljh/user/lib/python3.8/site-packages/google/analytics/data_v1beta/services/beta_analytics_data/client.py in run_report(self, request, retry, timeout, metadata)\r\n 491 \r\n 492 # Send the request.\r\n--> 493 response = rpc(\r\n 494 request,\r\n 495 retry=retry,\r\n\r\n/opt/tljh/user/lib/python3.8/site-packages/google/api_core/gapic_v1/method.py in __call__(self, timeout, retry, *args, **kwargs)\r\n 111 kwargs[\"metadata\"] = metadata\r\n 112 \r\n--> 113 return wrapped_func(*args, **kwargs)\r\n 114 \r\n 115 \r\n\r\n/opt/tljh/user/lib/python3.8/site-packages/google/api_core/grpc_helpers.py in error_remapped_callable(*args, **kwargs)\r\n 65 return callable_(*args, **kwargs)\r\n 66 except grpc.RpcError as exc:\r\n---> 67 raise exceptions.from_grpc_error(exc) from exc\r\n 68 \r\n 69 return error_remapped_callable\r\n\r\nPermissionDenied: 403 User does not have sufficient permissions for this property. To learn more about Property ID, see https://developers.google.com/analytics/devguides/reporting/data/v1/property-id.\r\n```\r\n\r\nI am unable to provide delegated access to properties using the same subject delegation that works in the GA3 API. I have searched to see if there is another scope for delegation in our Workspace account relative to this beta version. It is my understanding that `https://www.googleapis.com/auth/analytics.readonly` should provide this. We use a centralized Google Workspace email as a user on multiple GA4 properties to make reporting more efficient. Currently, we can't figure out how to unblock these permission denied errors using subject delgation, using code provided as example.","author":{"url":"https://github.com/jroakes","@type":"Person","name":"jroakes"},"datePublished":"2023-02-09T13:51:16Z","url":"https://github.com/googleapis/python-analytics-data/issues/341"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:498a440d-1488-a495-e65f-21116fd7adeb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 98B4:275045:186A95:1E6320:6B09EB48 |
| html-safe-nonce | c5d6a32fb16f99e86d8db87c183925e64f679966a9303a6a506db78cc2bb387b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OEI0OjI3NTA0NToxODZBOTU6MUU2MzIwOjZCMDlFQjQ4IiwidmlzaXRvcl9pZCI6IjY2MDk5NjkyNzc1MjM1ODU4NjQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2535c30d0858681ee5e45465aaa65671f03450e407086ed9e5d0a4423453264e |
| hovercard-subject-tag | issue:1577929354 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/python-analytics-data/341/issue_layout |
| twitter:image | https://opengraph.githubassets.com/63b524eaa4426af2d669e197618f4df00bf4eb8d21f8c7c6b0373f9c9c6356c7/googleapis/python-analytics-data/issues/341 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/63b524eaa4426af2d669e197618f4df00bf4eb8d21f8c7c6b0373f9c9c6356c7/googleapis/python-analytics-data/issues/341 |
| og:image:alt | Environment details OS type and version: Linux-5.4.0-1094-aws-x86_64-with-glibc2.17 Python version: Python 3.8.12 pip version: pip 21.2.4 google-analytics-data version: Version: 0.16.1 Steps to rep... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jroakes |
| hostname | github.com |
| expected-hostname | github.com |
| None | 29e6866c4c5b6697a062df08d37fa80bbfb75810ca4280c0d277f04956012d39 |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/python-analytics-data git https://github.com/googleapis/python-analytics-data.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 295544284 |
| octolytics-dimension-repository_nwo | googleapis/python-analytics-data |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 295544284 |
| octolytics-dimension-repository_network_root_nwo | googleapis/python-analytics-data |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e72aac8801621433bb0313888fbbe243f5998abc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width