particleflux/password-manager-connection

连接到外部密码/秘密管理器

4.0.0 2023-06-09 10:41 UTC

This package is auto-updated.

Last update: 2024-09-29 08:36:05 UTC


README

Packagist Version CircleCI Maintainability Test Coverage

将您的PHP应用程序连接到外部密码管理器。

安装

composer require particleflux/password-manager-connection

需求

  • 最低PHP 8.1

用法

use particleflux\PMConnection\PassConnection;

// initialize the connection client
$connection = new PassConnection();

// get the password for the account 'facebook'
$password = $connection->getPassword('facebook');

// get the username for the account 'facebook'
$username = $connection->getUser('facebook');

// get a custom attribute for an account
$email = $connection->getAttribute('facebook', 'email');

PassConnection

PassConnection 是连接到 pass 的特定实现。

$connection = new PassConnection([
    'prefix'        => 'social-media/',
    'userAttribute' => 'username',
]);

配置选项

prefix

应用于pass条目名称的前缀。

默认情况下,这是空的,这意味着提供给连接方法的 account 是完整的账户名称。然而,对于更复杂或更大的密码数据库,通常按 子文件夹 进行分组。可以使用前缀参数自动附加这些子文件夹。

例如,当将 prefix 设置为 social-media/ 时,调用 getPassword('facebook') 实际上会获取 social-media/facebook 的密码条目。

userAttribute

获取用户名的属性。

为了获取条目的密码之外的额外数据,通常会有特定的属性名称前缀。此选项配置用于获取用户名的属性名称。

以下是一个pass条目的例子

my-secret-password
username: my-username

此示例,使用 userAttributeusername,在调用 getUser() 时将返回 my-username