-
Notifications
You must be signed in to change notification settings - Fork 54
[SM-1266] Review PHP docs #878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
67cd747
SM-1266: Compose case sensitive imports
mzieniukbw d124c37
SM-1266: Consistent FFI library directories
mzieniukbw 1c4839a
SM-1266: Fix outdated secret get by ids command
mzieniukbw 54f4bdf
SM-1266: More verbose example
mzieniukbw 2beea1e
SM-1266: Composer lock update (excluding dependencies)
mzieniukbw d147f3b
SM-1266: PHP documentation update
mzieniukbw cb87747
Revert "SM-1266: Consistent FFI library directories"
mzieniukbw e58a8a9
SM-1266: Native library locations docs update
mzieniukbw 510ebb0
SM-1266: Native library locations relative to src
mzieniukbw 4a973df
Merge branch 'main' into sm/sm-1266-php-docs
vphan916 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# PHP Installation | ||
|
||
## Introduction | ||
|
||
Composer is used to build PHP Bitwarden client library. | ||
|
||
## Prerequisites | ||
|
||
- PHP >= 8.0 | ||
- FFI extension enabled in PHP configuration | ||
- Composer | ||
- Bitwarden SDK native library, which is expected in one of below locations, depending on the OS and architecture. | ||
If you prefer to build SDK yourself, see [SDK README.md](../../README.md) for instructions. | ||
- Windows: | ||
- x86_64: `C:\lib\windows-x64\bitwarden_c.dll`. | ||
- The drive letter is determined by the workdir of the PHP process, usually `C:` | ||
- Linux: | ||
- x86_64: `/lib/linux-x64/libbitwarden_c.so` | ||
- macOS: | ||
- x86_64: `./src/lib/macos-x64/libbitwarden_c.dylib` | ||
- aarch64: `./src/lib/macos-arm64/libbitwarden_c.dylib` | ||
- Where the `./src` is relative path to the [src](./src) directory. | ||
|
||
## Build Commands | ||
|
||
```shell | ||
composer install | ||
``` | ||
|
||
## Example | ||
|
||
### macOS | ||
|
||
#### Install Prerequisites | ||
|
||
Use brew Composer and PHP | ||
|
||
```shell | ||
brew install php | ||
brew install composer | ||
``` | ||
|
||
#### Build Commands | ||
|
||
```shell | ||
composer install | ||
``` | ||
|
||
## Example SDK Usage Project | ||
|
||
```shell | ||
export ACCESS_TOKEN="<access_token>" | ||
export ORGANIZATION_ID="<organization_id>" | ||
export API_URL="https://api.bitwarden.com" | ||
export IDENTITY_URL="https://identity.bitwarden.com" | ||
|
||
php example.php | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,114 @@ | ||
# Bitwarden Secrets Manager SDK wrapper for PHP | ||
|
||
PHP bindings for interacting with the [Bitwarden Secrets Manager]. This is a beta release and might be missing some functionality. | ||
Supported are CRUD operations on project and secret entities. | ||
PHP bindings for interacting with the [Bitwarden Secrets Manager]. This is a beta release and might be missing some | ||
functionality. | ||
|
||
## Installation | ||
|
||
Requirements: | ||
- PHP >= 8.0 | ||
- Composer | ||
- Bitwarden C libraries which you can generate using BitwardenSDK and following instructions in its readme (requires Rust). https://github.com/bitwarden/sdk | ||
If you are not using the standalone version of this library, file will be placed in `target/debug` folder if you are using from BitwardenSDK repository. | ||
- Access token for the Bitwarden account | ||
|
||
See the [installation instructions](./INSTALL.md) | ||
|
||
## Usage | ||
|
||
To interact with the client first you need to obtain the access token from Bitwarden. | ||
You can then initialize BitwardenSettings passing $api_url and $identity_url if needed. These parameteres are | ||
optional and if they are not defined, BitwardenSettings instance will try to get these values from ENV, and | ||
if they are not defined there as well, it will use defaults: `https://api.bitwarden.com` as api_url and | ||
`https://identity.bitwarden.com` as identity_url. You can also pass device type as argument but that is entirely | ||
optional. | ||
### Create access token | ||
|
||
Passing BitwardenSettings instance to BitwardenClient will initialize it. Before using the client you must | ||
be authorized by calling the access_token_login method passing your Bitwarden access token to it. | ||
To interact with the client first you need to obtain the access token from Bitwarden. | ||
Review the help documentation on [Access Tokens]. | ||
|
||
### Create new Bitwarden client | ||
|
||
```php | ||
$access_token = '<your token here>'; | ||
$api_url = "<api url>"; | ||
$identity_url = "<identity url>"; | ||
require_once 'vendor/autoload.php'; | ||
|
||
$access_token = '<access-token>'; | ||
$organization_id = "<organization-id>"; | ||
$api_url = "https://api.bitwarden.com"; | ||
$identity_url = "https://identity.bitwarden.com"; | ||
|
||
$bitwarden_settings = new \Bitwarden\Sdk\BitwardenSettings($api_url, $identity_url); | ||
|
||
$bitwarden_client = new \Bitwarden\Sdk\BitwardenClient($bitwarden_settings); | ||
$bitwarden_client->access_token_login($access_token); | ||
``` | ||
|
||
After successful authorization you can interact with client to manage your projects and secrets. | ||
```php | ||
$organization_id = "<your organization id here>"; | ||
Initialize `BitwardenSettings` by passing `$api_url` and `$identity_url` or set to null to use the defaults. | ||
The default for `api_url` is `https://api.bitwarden.com` and for `identity_url` is `https://identity.bitwarden.com`. | ||
|
||
$bitwarden_client = new \Bitwarden\Sdk\BitwardenClient($bitwarden_settings); | ||
$res = $bitwarden_client->access_token_login($access_token); | ||
### Create new project | ||
|
||
// create project | ||
$name = "PHP project" | ||
```php | ||
$name = "PHP project"; | ||
$res = $bitwarden_client->projects->create($name, $organization_id); | ||
$project_id = $res->id; | ||
``` | ||
|
||
### Get project | ||
|
||
// get project | ||
```php | ||
$res = $bitwarden_client->projects->get($project_id); | ||
``` | ||
|
||
### List all projects | ||
|
||
// list projects | ||
```php | ||
$res = $bitwarden_client->projects->list($organization_id); | ||
``` | ||
|
||
// update project | ||
$name = "Updated PHP project" | ||
$res = $bitwarden_client->projects->put($project_id, $name, $organization_id); | ||
### Update project | ||
|
||
// get secret | ||
$res = $bitwarden_client->secrets->get($secret_id); | ||
```php | ||
$name = "Updated PHP project"; | ||
$res = $bitwarden_client->projects->put($project_id, $name, $organization_id); | ||
``` | ||
|
||
// list secrets | ||
$res = $bitwarden_client->secrets->list($organization_id); | ||
### Delete project | ||
|
||
// delete project | ||
```php | ||
$res = $bitwarden_client->projects->delete([$project_id]); | ||
``` | ||
|
||
### Create new secret | ||
|
||
```php | ||
$key = "Secret key"; | ||
$note = "Secret note"; | ||
$value = "Secret value"; | ||
$res = $bitwarden_client->secrets->create($key, $note, $organization_id, [$project_id], $value); | ||
$secret_id = $res->id; | ||
``` | ||
|
||
Similarly, you interact with secrets: | ||
### Get secret | ||
|
||
```php | ||
$organization_id = "<your organization id here>"; | ||
$res = $bitwarden_client->secrets->get($secret_id); | ||
``` | ||
|
||
// create secret | ||
$key = "AWS secret key"; | ||
$note = "Private account"; | ||
$secret = "76asaj,Is_)" | ||
$res = $bitwarden_client->secrets->create($key, $note, $organization_id, [$project_id], $secret); | ||
$secret_id = $res->id; | ||
### Get multiple secrets | ||
|
||
// get secret | ||
$res = $bitwarden_sdk->secrets->get($secret_id); | ||
```php | ||
$res = $bitwarden_client->secrets->get_by_ids([$secret_id]); | ||
``` | ||
|
||
### List all secrets | ||
|
||
// list secrets | ||
```php | ||
$res = $bitwarden_client->secrets->list($organization_id); | ||
``` | ||
|
||
// update secret | ||
$note = "Updated account"; | ||
$key = "AWS private updated" | ||
$secret = "7uYTE,:Aer" | ||
$res = $bitwarden_client->secrets->update($secret_id, $key, $note, $organization_id, [$project_id], $secret); | ||
### Update secret | ||
|
||
// delete secret | ||
$res = $bitwarden_sdk->secrets->delete([$secret_id]); | ||
```php | ||
$key = "Updated key"; | ||
$note = "Updated note"; | ||
$value = "Updated value"; | ||
$res = $bitwarden_client->secrets->update($secret_id, $key, $note, $organization_id, [$project_id], $value); | ||
``` | ||
|
||
### Delete secret | ||
|
||
```php | ||
$res = $bitwarden_client->secrets->delete([$secret_id]); | ||
``` | ||
|
||
[Access Tokens]: https://bitwarden.com/help/access-tokens/ | ||
|
||
[Bitwarden Secrets Manager]: https://bitwarden.com/products/secrets-manager/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.