.NET 的 Google API 用戶端程式庫
client_secrets.json 用於儲存
client_id、client_secret 和其他 OAuth 2.0 參數。
client_secrets.json
檔案是 JSON 格式的檔案
,其中包含用戶端 ID、用戶端密鑰和其他 OAuth 2.0 參數。
以下是網頁應用程式的 client_secrets.json 範例檔案:
{
"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"
}
}
以下是已安裝應用程式的 client_secrets.json 範例檔案:
{
"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"
}
}這種格式定義了以下兩種用戶端 ID 類型的其中之一:
web:網頁應用程式。installed:已安裝的應用程式。
web 和 installed 子物件有
下列必要成員:
-
client_id(字串):用戶端 ID。 -
client_secret(字串):用戶端密鑰。
這個檔案的所有其他成員皆為選用, .NET 用戶端程式庫則不會用到。
動機
傳統上,OAuth 2.0 端點的供應商是
使用其服務複製及貼上用戶端 ID 的使用者
轉換為有效程式碼
這個方法容易出錯,並提供不完整的圖片
確保 OAuth 2.0 運作所需的資訊。
(OAuth 2.0 也需要知道所有端點,
並設定重新導向 URI)。
如果服務供應商提供可下載的 client_secrets.json
檔案和用戶端程式庫
那麼導入 OAuth 2.0 不僅更簡單,也較不容易出錯。