wordpress - 保护公共 WP 插件中使用的 Google API 密钥
问题描述
今天是个好日子,
我计划构建一个需要 Google Search Console API 的 WP 插件。目标是不要将我的 API 密钥和客户端 ID 与插件一起发送。
- WP 插件 -> 从 domain.com 请求数据
- domain.com 从 Google Search Console API 请求数据
- domain.com 将数据发送到 WP 插件而不保存它
- WP Plugin 将数据保存在安装位置
我可以知道这是否可能以及我需要做什么?
谢谢,
编辑:2 月 16 日
我发现这可以通过从客户端验证用户来完成(wp插件)
require_once dirname(__FILE__) . '/vendor/autoload.php';
$client = new Google_Client();
$client->setScopes( array( 'https://www.googleapis.com/auth/webmasters', 'https://www.googleapis.com/auth/webmasters.readonly' ) );
$client->setAccessType( 'offline' );
$client->setRedirectUri( 'urn:ietf:wg:oauth:2.0:oob' );
$client->setClientId( '302343592020-r7ouc9s9jaukc54j48s3k9fg26eeiaqr.apps.googleusercontent.com' );
$client->setIncludeGrantedScopes(true);
//Generate access code from the link below
//echo '<a href="'.$client->createAuthUrl().'" target="_blank">Access Code</a>';
$code = '###############';
$client->authenticate($code); $access_token = $client->getAccessToken();
但是,访问令牌为空
解决方案
我会将这个问题标记为已解决。
我开始意识到 WP Plugin 可以通过我的域进行身份验证以获取访问令牌。然后使用访问令牌直接从 wp_plugin 调用 google api。
这样我就不会连同插件源代码一起发送我的客户端密码。
推荐阅读
- python - Python clr 找不到 dll
- php - 单选按钮值无法插入数据库。我该如何解决这个问题?
- node.js - 'w' 不是内部或外部命令、可运行程序或批处理文件
- python - kivy中的深层链接
- javascript - 如何使用鼠标滚轮事件禁用 addEventListener
- exe - C# - 为什么 costura 和 fody 对我不起作用?
- python - REST API 会话的 SQLAlchemy 最佳实践
- python - 命名索引中的所有分组变量
- android - 更改 Android 中活动或非活动选项卡的文本大小
- sql - 如何在两个值之间生成数字