Skip to content

particleflux/password-manager-connection

Repository files navigation

password-manager-connection

Packagist Version CircleCI Maintainability Test Coverage

Connect your PHP app to an external password manager.

Installation

composer require particleflux/password-manager-connection

Requirements

  • minimum PHP 8.1

Usage

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 is a specific implementation to connect with pass.

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

Configuration options

prefix

A prefix applied to the pass entry name.

By default, this is empty, meaning that the account given to the connection methods is the complete account name. When having more complex or bigger password databases though, it is common to group them by subfolders. These subfolders can be auto-appended by using the prefix parameter.

For example, when setting prefix to social-media/, the call to getPassword('facebook') will actually get the password entry for social-media/facebook.

userAttribute

The attribute to get the username.

To have additional data besides the password for an entry, it is common to have specific attribute name prefixes. This options configures the attribute name used for getting the username.

Taking this pass entry for example:

my-secret-password
username: my-username

This example, with the userAttribute of username, will return my-username in a call to getUser().