با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
Google Sign-In چرخه عمر توکن و جریان OAuth 2.0 را مدیریت می کند و ادغام شما با APIهای Google را ساده می کند. کاربر همیشه این گزینه را دارد که در هر زمانی دسترسی به یک برنامه را لغو کند .
این سند نحوه تکمیل یک ادغام اولیه ورود به سیستم Google را شرح می دهد.
اعتبارنامه مجوز ایجاد کنید
هر برنامهای که از OAuth 2.0 برای دسترسی به APIهای Google استفاده میکند، باید دارای اعتبارنامه مجوز باشد که برنامه را در سرور OAuth 2.0 Google شناسایی کند. مراحل زیر نحوه ایجاد اعتبار برای پروژه خود را توضیح می دهد. سپس برنامه های شما می توانند از اعتبارنامه ها برای دسترسی به API هایی که برای آن پروژه فعال کرده اید استفاده کنند.
کلاینت OAuth 2.0 خود را نام ببرید و روی ایجاد کلیک کنید
پس از تکمیل پیکربندی، شناسه مشتری ایجاد شده را یادداشت کنید. برای تکمیل مراحل بعدی به شناسه مشتری نیاز دارید. (یک رمز مشتری نیز ایجاد می شود، اما شما فقط برای عملیات سمت سرور به آن نیاز دارید.)
کتابخانه پلتفرم Google را بارگیری کنید
شما باید کتابخانه پلتفرم Google را در صفحات وب خود که Google Sign-In را یکپارچه می کنند، قرار دهید.
ساده ترین راه برای افزودن دکمه ورود به سیستم گوگل به سایت خود استفاده از دکمه ورود به سیستم است که به صورت خودکار ارائه می شود. تنها با چند خط کد، میتوانید دکمهای اضافه کنید که بهطور خودکار خودش را به گونهای پیکربندی میکند که متن، آرم و رنگهای مناسب برای وضعیت ورود کاربر و محدودههای درخواستی شما را داشته باشد.
برای ایجاد یک دکمه ورود به سیستم Google که از تنظیمات پیشفرض استفاده میکند، یک عنصر div با کلاس g-signin2 به صفحه ورود به سیستم خود اضافه کنید:
پس از اینکه با استفاده از دامنه های پیش فرض کاربر با Google وارد سیستم شدید، می توانید به شناسه Google، نام، URL نمایه و آدرس ایمیل کاربر دسترسی داشته باشید.
برای بازیابی اطلاعات پروفایل یک کاربر، از متد getBasicProfile() استفاده کنید.
میتوانید با افزودن دکمه خروج یا پیوند به سایت خود، کاربران را قادر به خروج از برنامه خود بدون خروج از Google کنید. برای ایجاد پیوند خروج، تابعی را که متد GoogleAuth.signOut() را فراخوانی میکند به رویداد onclick پیوند متصل کنید.
<ahref="#"onclick="signOut();">Signout</a>
<script>
functionsignOut(){varauth2=gapi.auth2.getAuthInstance();auth2.signOut().then(function(){console.log('User signed out.');});}
</script>
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eGoogle Sign-In is being deprecated; developers should consult the Deprecation and Sunset guide for more information and migration strategies.\u003c/p\u003e\n"],["\u003cp\u003eTo integrate Google Sign-In, you must create authorization credentials in the Google Developers Console and include the Google Platform Library in your web pages.\u003c/p\u003e\n"],["\u003cp\u003eYou can easily add a Google Sign-In button using a provided HTML snippet and retrieve basic user profile information after sign-in.\u003c/p\u003e\n"],["\u003cp\u003eFor server-side authentication, it is crucial to use ID tokens instead of relying on Google IDs or profile information directly.\u003c/p\u003e\n"],["\u003cp\u003eUsers can sign out of your application without signing out of Google using the provided sign-out method.\u003c/p\u003e\n"]]],[],null,["| **Warning:** The Google Sign-In library optionally uses FedCM APIs, and their use will become a requirement. [Conduct an impact assessment](/identity/sign-in/web/gsi-with-fedcm) to confirm that user sign-in continues to function as expected. \n|\nSupport for the Google Sign-In library is deprecated, see the [Deprecation and Sunset](/identity/sign-in/web/deprecation-and-sunset) guide for more. \n\nGoogle Sign-In manages the OAuth 2.0 flow and token lifecycle,\nsimplifying your integration with Google APIs. A user always has the option to\n[revoke access](https://myaccount.google.com/permissions) to an\napplication at any time.\n\nThis document describes how to complete a basic Google Sign-In integration.\n\nCreate authorization credentials\n\nAny application that uses OAuth 2.0 to access Google APIs must have authorization credentials\nthat identify the application to Google's OAuth 2.0 server. The following steps explain how to\ncreate credentials for your project. Your applications can then use the credentials to access APIs\nthat you have enabled for that project.\n\n1. Go to the [Clients page](https://console.developers.google.com/auth/clients).\n2. Click **Create Client**.\n3. Select the **Web application** application type.\n4. Name your OAuth 2.0 client and click **Create**\n\nAfter configuration is complete, take note of the client ID that was created.\nYou will need the client ID to complete the next steps. (A client secret is also\ncreated, but you need it only for server-side operations.)\n\nLoad the Google Platform Library\n\nYou must include the Google Platform Library on your web pages that integrate\nGoogle Sign-In. \n\n \u003cscript src=\"https://apis.google.com/js/platform.js\" async defer\u003e\u003c/script\u003e\n\nSpecify your app's client ID\n\nSpecify the client ID you created for your app in the Google Developers Console\nwith the `google-signin-client_id` meta element. \n\n```\n\u003cmeta name=\"google-signin-client_id\" content=\"YOUR_CLIENT_ID.apps.googleusercontent.com\"\u003e\n```\n| **Note:** You can also specify your app's client ID with the `client_id` parameter of the [`gapi.auth2.init()`](/identity/sign-in/web/reference#gapiauth2initparams) method.\n\nAdd a Google Sign-In button\n\nThe easiest way to add a Google Sign-In button to your site is to use an\nautomatically rendered sign-in button. With only a few lines of code, you can\nadd a button that automatically configures itself to have the appropriate text,\nlogo, and colors for the sign-in state of the user and the scopes you request.\n\nTo create a Google Sign-In button that uses the default settings, add a `div`\nelement with the class `g-signin2` to your sign-in page: \n\n \u003cdiv class=\"g-signin2\" data-onsuccess=\"onSignIn\"\u003e\u003c/div\u003e\n\nGet profile information\n\nAfter you have signed in a user with Google using the default scopes, you can\naccess the user's Google ID, name, profile URL, and email address.\n\nTo retrieve profile information for a user, use the\n[`getBasicProfile()`](/identity/sign-in/web/reference#googleusergetbasicprofile)\nmethod. \n\n function onSignIn(googleUser) {\n var profile = googleUser.getBasicProfile();\n console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.\n console.log('Name: ' + profile.getName());\n console.log('Image URL: ' + profile.getImageUrl());\n console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.\n }\n\n| **Important:** Do not use the Google IDs returned by `getId()` or the user's profile information to communicate the currently signed in user to your backend server. Instead, [send ID tokens](/identity/sign-in/web/backend-auth), which can be securely validated on the server.\n\nSign out a user\n\nYou can enable users to sign out of your app without signing out of Google by\nadding a sign-out button or link to your site. To create a sign-out link, attach\na function that calls the\n[`GoogleAuth.signOut()`](/identity/sign-in/web/reference#googleauthsignout)\nmethod to the link's `onclick` event. \n\n \u003ca href=\"#\" onclick=\"signOut();\"\u003eSign out\u003c/a\u003e\n \u003cscript\u003e\n function signOut() {\n var auth2 = gapi.auth2.getAuthInstance();\n auth2.signOut().then(function () {\n console.log('User signed out.');\n });\n }\n \u003c/script\u003e"]]