دسترسی به ویژگی های هویت کاربر
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
کاربران از رابط انجمن شما برای ایجاد منابع داده خود استفاده خواهند کرد. برای این منابع داده، رابط شما میتواند به هویت کاربر مؤثر دسترسی داشته باشد. بسته به اعتبار منبع داده ، کاربر مؤثر میتواند خالق منبع داده (مدارک اعتبار) یا مشاهدهکننده گزارش (اعتبارنامه بیننده) باشد.
فواید
- شما می توانید از طرف کاربر به سرویس ها و API های Google دسترسی داشته باشید.
- شما می توانید کنترل دسترسی سفارشی را برای اطمینان از نمایش داده های مربوطه پیاده سازی کنید.
- شما می توانید تجربه کاربری را برای کاربر موثر سفارشی کنید.
مراحل پیاده سازی
دسترسی به نشانه OAuth کاربر
رابط شما میتواند از طرف کاربر با عبور دادن رمز OAuth کاربر به خدمات و APIهای Google دسترسی داشته باشد. برای دسترسی به نشانه OAuth کاربر موثر در رابط خود، از ScriptApp.getOAuthToken()
استفاده کنید. مرجع getOAuthToken را ببینید. این نشانه شامل محدوده های مجوز موجود در طول مجوز اتصال است.
برای اکثر رابطها، Apps Script بهطور خودکار با تجزیه و پردازش اسکریپت، محدودههای مورد نیاز را تشخیص میدهد. میتوانید دامنههایی را که یک رابط استفاده میکند در هر زمان مشاهده کنید . همچنین میتوانید با استفاده از رشتههای URL، دامنهها را به صراحت در مانیفست خود تنظیم کنید. اگر میخواهید از طرف کاربر به سرویس یا API Google دسترسی داشته باشید، آن محدوده مربوطه را در مانیفست قرار دهید.
دسترسی به آدرس ایمیل کاربر
در کد خود، می توانید کاربر موثر فعلی را با Session.getEffectiveUser().getEmail()
شناسایی کنید. مرجع getEffectiveUser را ببینید. افزودن این کد به طور خودکار محدوده مجوز https://www.googleapis.com/auth/userinfo.email
را به رابط شما اضافه می کند.
مثال: فراخوانی APIهای Google با توکن OAuth کاربر
- رابط Google Fit دادهها را از Google Fit API برای کاربر مؤثر واکشی میکند. هنگام فراخوانی API، توکن OAuth کاربر موثر را پاس می کند. برای جزئیات پیاده سازی به کد منبع مراجعه کنید.
- رابط Firestore از Cloud Resource Manager برای دریافت لیستی از پروژه ها برای کاربر مؤثر استفاده می کند. این کانکتور توکن OAuth کاربر موثر را نیز ارسال می کند. برای جزئیات پیاده سازی به کد منبع مراجعه کنید.
مثال: isAdminUser()
بر اساس آدرس ایمیل
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eCommunity Connectors allow you to build data sources that can access the effective user's identity, enabling personalized data retrieval.\u003c/p\u003e\n"],["\u003cp\u003eDepending on the data source credentials, the effective user can be either the data source creator or the report viewer.\u003c/p\u003e\n"],["\u003cp\u003eYour connector can leverage the user's OAuth token to access Google services and APIs on their behalf for custom data integrations.\u003c/p\u003e\n"],["\u003cp\u003eYou can tailor the user experience by implementing custom access control and using the user's email address for identification.\u003c/p\u003e\n"]]],[],null,["# Access user identity properties\n\nUsers will use your Community Connector to create their own data sources. For\nthese data sources, your connector can access the effective user's identity.\nDepending on the [Data source credentials](https://support.google.com/looker-studio/answer/6371135), the effective user can be the data\nsource creator (Owner's credentials) or the report viewer (Viewer's\ncredentials).\n\nBenefits\n--------\n\n- You can access Google services and APIs on behalf of the user.\n- You can implement custom access control to ensure only relevant data is being displayed.\n- You can customize the user experience for the effective user.\n\nImplementation steps\n--------------------\n\n### Accessing the user OAuth token\n\nYour connector can access Google services and APIs on behalf of the user by\npassing the user's OAuth token. To access the effective user's OAuth token in\nyour connector, use `ScriptApp.getOAuthToken()`. See [getOAuthToken reference](/apps-script/reference/script/script-app#getoauthtoken).\nThis token will include the [Authorization scopes](/apps-script/concepts/scopes) included during the connector\nauthorization.\n\nFor most connectors, Apps Script automatically detects what scopes are needed by\nparsing and processing the script. You can [view the scopes](/apps-script/concepts/scopes#viewing_scopes) a connector uses at\nany time. You can also [set scopes explicitly](/apps-script/concepts/scopes#setting_explicit_scopes) in your [manifest](/apps-script/concepts/manifests) using URL\nstrings. If you want to access a Google service or API on behalf of the user,\ninclude that relevant scope in the manifest.\n\n### Accessing the user email address\n\nIn your code, you can identify the current effective user with\n`Session.getEffectiveUser().getEmail()`. See [getEffectiveUser reference](/apps-script/reference/base/session#getEffectiveUser).\nAdding this code will automatically add the\n`https://www.googleapis.com/auth/userinfo.email` authorization scope to your\nconnector.\n\nExample: Calling Google APIs with user OAuth token\n--------------------------------------------------\n\n- The [Google Fit connector](https://lookerstudio.google.com/datasources/create?connectorId=AKfycbwFrL1OLXR3wqfnxowGFF3w3D4eq-54vAwjxDWcWRjiZMxX7jhII_1Ddx6y76GDHrxIew) fetches data from the Google Fit API for the effective user. While calling the API, it passes the effective user's OAuth token. See [the source code](https://github.com/googledatastudio/community-connectors/blob/master/google-fit/src/GoogleFit.js#L245) for implementation details.\n- The [Firestore connector](https://github.com/googledatastudio/community-connectors/tree/master/firestore) uses the Cloud Resource Manager to get a list of projects for the effective user. This connector also passes the effective user's OAuth token. See [the source code](https://github.com/googledatastudio/community-connectors/blob/master/firestore/src/GoogleCloud.gs#L30) for implementation details.\n\nExample: `isAdminUser()` based on email address\n-----------------------------------------------\n\n- The [Chrome UX Connector](http://g.co/chromeuxdash) maintains a list of admin users. It uses `getEffectiveUser()` and compares the effective user against the list to determine whether the effective user is an admin or not. See [implementation of `getEffectiveUser`](https://github.com/googledatastudio/community-connectors/blob/master/chrome-ux-report/src/Code.js#L581)."]]