Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在开源(Github+;Heroku)应用程序中保护Google API密钥_Php_Heroku_Github_Google Api_Google Calendar Api - Fatal编程技术网

Php 如何在开源(Github+;Heroku)应用程序中保护Google API密钥

Php 如何在开源(Github+;Heroku)应用程序中保护Google API密钥,php,heroku,github,google-api,google-calendar-api,Php,Heroku,Github,Google Api,Google Calendar Api,我正在创建一个我希望在未来几周内开源的应用程序。源代码在Github上,如果通过Travis CI测试,Heroku会在有新提交时自动部署代码 在这个应用程序中,我通过在heroku dynos中使用env变量,成功地将几个API键保留在开源存储库之外 但是,对于googleserver-to-server API,我必须有一个.p12文件。在php中,以下内容将对我的客户端进行身份验证: $client = new Google_Client(); $client->setApplica

我正在创建一个我希望在未来几周内开源的应用程序。源代码在Github上,如果通过Travis CI测试,Heroku会在有新提交时自动部署代码

在这个应用程序中,我通过在heroku dynos中使用env变量,成功地将几个API键保留在开源存储库之外

但是,对于googleserver-to-server API,我必须有一个
.p12
文件。在php中,以下内容将对我的客户端进行身份验证:

$client = new Google_Client();
$client->setApplicationName("Client_Calendar");
$service = new Google_Service_Calendar($client);

$key = file_get_contents('myKey.p12');
var_dump($key);

$cred = new Google_Auth_AssertionCredentials(
  'xxx@gserviceaccount.com',
  array('https://www.googleapis.com/auth/calendar'),
  $key
);

$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired()) {
  $client->getAuth()->refreshTokenWithAssertion($cred);
}

...

$event = $service->events->insert($calendarId, $event, $sendNotifications);
起初,我认为可以提取
$key
变量的内容,并将其插入另一个heroku环境变量中,但内容是加密的

所以,这里有一个问题:如何保护您的
.p12
密钥不在开源存储库中被盗


PS:我只需创建谷歌日历事件并向与会者发送通知;如果您知道一种不用
.p12
文件就能做到这一点的方法,我洗耳恭听。

不要提交它。说真的,就这么简单。你在正确的轨道上。事实上,即使在这里发布,您也可能想要请求一个新密钥


有一个建议是将整个配置文件存储在可能需要您可以存储的凭据的其他位置。S3是一个适合这种事情的好地方。S3也有一个惊人的PHP组件,用于访问S3存储桶。

如果可以将文件内容移动到环境变量中,为什么文件内容与问题“加密”相关?因为Heroky只接受Key=>Value String作为环境变量,而我从.p12文件中只能看到问号。当然,这就是环境变量的工作原理。google键是值,而不是键/值组合。你对内容的意思不感兴趣,我同意。但我无法获取文件的内容。要打开它,我需要一个据我所知谷歌没有提供的密码,以及“var_dump($key);”只打印“?”。对不起,我看不懂。如果由于缺少凭据而无法打开文件,那么如何获取内容并将其转储?我听从了您的建议。另一个具有访问配置文件凭据的dyno。