API 憑證應該存儲在 laravel 中的哪個位置? (Where API credentials should be stored in laravel?)


問題描述

API 憑證應該存儲在 laravel 中的哪個位置? (Where API credentials should be stored in laravel?)

我們正在為 laravel 開發包,它通過 API 與另一個應用程序交互。目前我們正在緩存中存儲 api 憑據。每當緩存被清除時,連接中斷。我們正在考慮替代方案。這是將這些憑據存儲在數據庫中的好習慣嗎?如果是,它將如何刷新下一個憑據?


參考解法

方法 1:

I would recommend adding a config file for them which loads them from the .env file. You can largely mimic the database credential infrastructural for this. This allows you to isolate the information in a single file, and keep them out of git completely. It also allows you to modify them per environment if you have a separate endpoint and/or credentials for the api which you can use in local or any uat environments.

.env:

THIRD_PARTY_API_USERNAME=test
THIRD_PARTY_API_PASSWORD=test

config/third‑party.php

<?php

return [
  'username' => env('THIRD_PARTY_API_USERNAME', null),
  'password' => env('THIRD_PARTY_API_PASSWORD', null),
];

usage:

$password = config('third_party.password');

方法 2:

I think you should have enough control over your caching mechanism, to ensure when it's cleared, right?

On the other hand, surely you can use a database. Just make a new table where you store at least the key and a timestamp. This way you can always find out how old the key is and just replace it by a new one.

(by user13815476James Clarkwschopohl)

參考文件

  1. Where API credentials should be stored in laravel? (CC BY‑SA 2.5/3.0/4.0)

#API #laravel-5 #Laravel #package






相關問題

UPS Api - php, làm cách nào để truy cập? (UPS Api - php, how do I get around?)

Google api 地圖和主幹錯誤 (Google api maps and backbone error)

如何將數據從控制器傳遞到 go lang 中的表單? (How can I pass data from controller to form in go lang?)

從 ASP.net 使用 PHP 中的 POST 數據抓取數據 (Scraping data with POST data in PHP from ASP.net)

檢測/指紋手機品牌和型號的替代方法? (Alternative way to detect/fingerprint phone make and model?)

POST:get_responses API 未提供所需數據 (POST : get_responses API not giving required data)

通過 API 檢測 Shopware 版本 (Detect Shopware Version through API)

我的 module.exports 返回為 [object Object] (My module.exports return as [object Object])

API 憑證應該存儲在 laravel 中的哪個位置? (Where API credentials should be stored in laravel?)

Uppy "PUT" XHR(multipart/form-data) 請求結果清空 Laravel $request 數組 (Uppy "PUT" XHR(multipart/form-data) request results to empty Laravel $request array)

JObject 不包含“user_name”的定義,也沒有可訪問的擴展方法“user_name” (JObject does not contain a definition for 'user_name' and no accessible extension method 'user_name')

PUT API 中的 Django Rest Framework 解析錯誤 (Django Rest Framework parse error in PUT API)







留言討論