如要這樣做,您可以從已透過 Identity Platform 登入的用戶端應用程式中擷取 ID 權杖,並在向伺服器提出的要求中加入該權杖。接著,伺服器會驗證 ID 權杖,並擷取用於識別使用者的宣告 (包括 uid、使用者登入時所用的 ID 提供者等)。您的伺服器就能使用這項身分資訊,代表使用者執行動作。
Firebase Admin SDK 提供方法,可讓您管理使用者、產生自訂權杖,以及驗證 ID 權杖,以便完成上述驗證作業。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[[["\u003cp\u003eThe Firebase Admin SDK enables server-side integration with Identity Platform for managing users, authentication tokens, and identity verification.\u003c/p\u003e\n"],["\u003cp\u003eYou can programmatically manage users, including retrieving full user data and modifying credentials, using the admin user management API without needing existing user credentials.\u003c/p\u003e\n"],["\u003cp\u003eCustom tokens allow integration with external user systems or unsupported identity providers, enabling users to sign in to Identity Platform and access other services.\u003c/p\u003e\n"],["\u003cp\u003eID tokens can be verified on your server to securely identify signed-in users and perform server-side logic on their behalf.\u003c/p\u003e\n"],["\u003cp\u003eCustom user claims, managed via the Firebase Admin SDK, allow for fine-grained access control for users signed in with any supported Identity Platform auth provider.\u003c/p\u003e\n"]]],[],null,["# Introduction to the Admin Auth API\n==================================\n\nIdentity Platform is built on an enhanced infrastructure that supports\nauthentication of users to your apps and services. You can use the\nFirebase Admin SDK to integrate your own servers with Identity Platform and\nmanage your users or authentication tokens. There are a number of\nreasons you would want to do this:\n\n**User Management**\n\nIt is not always convenient to have to visit the\n\nGoogle Cloud console (Google Cloud console)\nto manage your Identity Platform users. The admin user management API\nprovides programmatic access to those same users. It even allows you to do\nthings the\nGoogle Cloud console cannot, such as\nretrieving a user's full data and changing a user's password, email address, or\nphone number.\n\n**Custom Authentication**\n\nYou can integrate an external user system with Identity Platform. For\nexample, you may already have a pre-existing user database or you may want to\nintegrate with a third-party identity provider that Identity Platform doesn't natively\nsupport.\n\nTo do this, you can create custom tokens with arbitrary claims identifying the\nuser. These custom tokens can then be used to sign into the Identity Platform service on\na client application and assume the identity described by the token's claims.\nThis identity will then be used when accessing other Identity Platform\nservices, such as Cloud Storage.\n\n**Identity Verification**\n\nIdentity Platform is primarily used to identify users of your app in order to restrict\naccess to other services, like Cloud Storage.\nYou can also use the service to identify these users on your own server. This\nlets you securely perform server-side logic on behalf of users that have signed\nin with Identity Platform.\n\nTo do this, you can retrieve an ID token from a client\napplication signed in with Identity Platform and include the token in a request to your\nserver. Your server then verifies the ID token and extracts the claims that\nidentify the user (including their `uid`, the identity provider they logged in\nwith, etc.). This identity information can then be used by your server to carry\nout actions on behalf of the user.\n\nThe Firebase Admin SDK provides methods for accomplishing the\nauthentication tasks above by enabling you to manage your users, generate custom\ntokens, and verify ID tokens.\n\n**Custom User Claims**\n\nIn some cases, you may want to implement fine-grained access control\nfor users already signed in with one of the supported Identity Platform\nauth providers such as Email/Password, Google, Facebook, phone, etc. A\ncombination of custom user claims and application security rules provides this\ncapability. For example, a user signed in with the Identity Platform Email and\nPassword provider can have access control defined using custom claims.\n\nUser management\n---------------\n\nThe Firebase Admin SDK provides an API for managing your\nIdentity Platform users with elevated privileges. The admin user management\nAPI gives you the ability to programmatically retrieve, create, update, and\ndelete users without requiring a user's existing credentials and without\nworrying about client-side rate limiting.\n[Manage users](/identity-platform/docs/concepts-manage-users)\n\nCustom token creation\n---------------------\n\nThe primary use for creating custom tokens is to allow users to authenticate\nagainst an external or legacy authentication mechanism. This could be one you\ncontrol, such as your LDAP server, or a third-party OAuth provider which\nIdentity Platform does not natively support, such as Instagram or LinkedIn.\n\nThe Firebase Admin SDK has a built-in method for creating\ncustom tokens. You can also programmatically create custom tokens in any\nlanguage using third-party JWT libraries.\n\nYour server should create a custom token with a unique identifier (`uid`) and\npass that token to a client app, which will use it to sign in to\nIdentity Platform. See\n[Create custom tokens](https://firebase.google.com/docs/auth/admin/create-custom-tokens)\nfor code samples and more details about the custom token creation process.\n\nID token verification\n---------------------\n\nIf your Identity Platform client app communicates with your backend server,\nyou might need to identify the currently signed-in user on your server so you\ncan perform server-side logic on their behalf. You can do this securely by using\nID tokens, which are created by Identity Platform when a user signs into an\nIdentity Platform app. ID tokens conform to the\n[OpenID Connect spec](http://openid.net/specs/openid-connect-core-1_0.html) and\ncontain data to identify a user, as well as some other profile and\nauthentication related information. You can send, verify,\nand inspect these tokens from your own backends. This allows you to securely\nidentify the currently signed in user and authorize them into your own backend\nresources.\n\nThe Firebase Admin SDK has a built-in method for verifying\nID tokens. You can also programmatically verify ID tokens in any\nlanguage using third-party JWT libraries. See\n[Verify ID tokens](https://firebase.google.com/docs/auth/admin/verify-id-tokens)\nfor more details and code samples about the ID token verification process.\n\nCustom user claims\n------------------\n\nThe Firebase Admin SDK lets you set custom attributes on user accounts.\nWith custom user claims, you can give users different levels of access (roles),\nwhich are then enforced in an application's security rules.\n\nAfter custom claims are modified on a user via the Firebase Admin SDK, they are\npropagated to the authenticated users on the client side via their ID tokens.\nThe ID token is a trusted mechanism for delivering\nthese custom claims, and all authenticated access must validate the ID token\nbefore processing the associated request.\n\n[Control Access with Custom Claims](https://firebase.google.com/docs/auth/admin/custom-claims)"]]