Mật khẩu ứng dụng
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Thư viện ứng dụng API của Google dành cho .NET sử dụng client_secrets.json
tệp để lưu trữ client_id
, client_secret
và các tham số OAuth 2.0 khác.
Một client_secrets.json
là tệp có định dạng JSON chứa mã ứng dụng khách, mật khẩu ứng dụng khách và các tham số OAuth 2.0 khác. Dưới đây là tệp client_secrets.json
mẫu cho một ứng dụng web:
{ "web": { "client_id": "asdfjasdljfasdkjf", "client_secret": "1912308409123890", "redirect_uris": ["https://www.example.com/oauth2callback"], "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://accounts.google.com/o/oauth2/token" } }
Dưới đây là tệp client_secrets.json
mẫu cho một ứng dụng đã cài đặt:
{ "installed": { "client_id": "837647042410-75ifg...usercontent.com", "client_secret":"asdlkfjaskd", "redirect_uris": ["http://localhost"], "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://accounts.google.com/o/oauth2/token" } }
Định dạng xác định một trong hai loại mã ứng dụng khách:
web
: Ứng dụng web. installed
: Ứng dụng đã được cài đặt.
Các đối tượng phụ web
và installed
có các thành viên bắt buộc sau:
-
client_id
(chuỗi): Mã ứng dụng khách. -
client_secret
(chuỗi): Mật khẩu ứng dụng khách.
Tất cả các thành phần khác của tệp này là không bắt buộc và thư viện ứng dụng .NET không sử dụng các mã này.
Động lực
Thông thường, nhà cung cấp điểm cuối OAuth 2.0 dự kiến sẽ có những người sử dụng dịch vụ của họ để sao chép và dán mã ứng dụng khách và mật khẩu ứng dụng khách từ trang đăng ký vào mã đang hoạt động. Phương thức này dễ gặp lỗi và đưa ra hình ảnh không đầy đủ thông tin cần thiết để OAuth 2.0 hoạt động. (OAuth 2.0 cũng yêu cầu biết tất cả các điểm cuối, và định cấu hình URI chuyển hướng.) Nếu nhà cung cấp dịch vụ cung cấp client_secrets.json
có thể tải xuống tệp và thư viện ứng dụng được chuẩn bị để sử dụng các tệp này, thì việc triển khai OAuth 2.0 sẽ dễ dàng hơn và ít gặp lỗi hơn.
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[[["\u003cp\u003eThe Google APIs client library for .NET utilizes \u003ccode\u003eclient_secrets.json\u003c/code\u003e files to store OAuth 2.0 credentials like \u003ccode\u003eclient_id\u003c/code\u003e, \u003ccode\u003eclient_secret\u003c/code\u003e, and other parameters.\u003c/p\u003e\n"],["\u003cp\u003eThese JSON files define client ID types as either \u003ccode\u003eweb\u003c/code\u003e for web applications or \u003ccode\u003einstalled\u003c/code\u003e for installed applications, each requiring \u003ccode\u003eclient_id\u003c/code\u003e and \u003ccode\u003eclient_secret\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eUsing \u003ccode\u003eclient_secrets.json\u003c/code\u003e files simplifies OAuth 2.0 implementation by providing a centralized, downloadable configuration instead of manual entry, reducing errors.\u003c/p\u003e\n"]]],[],null,["The Google APIs client library for .NET uses\n`client_secrets.json` files for storing the\n`client_id`, `client_secret`, and other OAuth 2.0 parameters.\n\nA `client_secrets.json`\nfile is a [JSON](http://www.json.org/) formatted file\ncontaining the client ID, client secret, and other OAuth 2.0 parameters.\nHere is an example `client_secrets.json` file for a web application: \n\n```\n{\n \"web\": {\n \"client_id\": \"asdfjasdljfasdkjf\",\n \"client_secret\": \"1912308409123890\",\n \"redirect_uris\": [\"https://www.example.com/oauth2callback\"],\n \"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\",\n \"token_uri\": \"https://accounts.google.com/o/oauth2/token\"\n }\n}\n```\n\n\nHere is an example `client_secrets.json` file for an installed application: \n\n```\n{\n \"installed\": {\n \"client_id\": \"837647042410-75ifg...usercontent.com\",\n \"client_secret\":\"asdlkfjaskd\",\n \"redirect_uris\": [\"http://localhost\"],\n \"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\",\n \"token_uri\": \"https://accounts.google.com/o/oauth2/token\"\n }\n}\n```\n\n\nThe format defines one of two client ID types:\n\n- `web`: Web application.\n- `installed`: Installed application.\n\n\nThe `web` and `installed` sub-objects have\nthe following mandatory members:\n\n- `client_id` (string): The client ID.\n- `client_secret` (string): The client secret.\n\n\nAll the other members of this file are optional and\nthe .NET client library doesn't use them.\n\nMotivation\n\n\nTraditionally, providers of OAuth 2.0 endpoints have expected\nthose who use their services to copy and paste the client ID\nand client secret from a registration page into working code.\nThis method is error-prone and gives an incomplete picture\nof the information that is needed to get OAuth 2.0 working.\n(OAuth 2.0 also requires knowing all the endpoints,\nand configuring a redirect URI.)\n\nIf service providers provide downloadable `client_secrets.json`\nfiles, and client libraries are prepared to consume these files,\nthen implementing OAuth 2.0 will be easier and less prone to error."]]