-
Notifications
You must be signed in to change notification settings - Fork 54
SM-1402 - review and update php sdk #1032
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
Merged
Merged
Changes from all commits
Commits
Show all changes
42 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 7f03f3e
feat: `login_access_token` with state_file; update examples
tangowithfoxtrot 4a973df
Merge branch 'main' into sm/sm-1266-php-docs
vphan916 862431c
Merge branch 'main' into sm-1402-review-and-update-php-sdk
tangowithfoxtrot 6c6cd36
Merge branch 'main' into sm-1402-review-and-update-php-sdk
tangowithfoxtrot 00b1647
fix: getbyids
tangowithfoxtrot c8ae6b1
refactor: projects.put -> projects.update
tangowithfoxtrot 513b888
feat: secret syncing
tangowithfoxtrot 5f8d322
Manually generated secretSyncRequest schema
tangowithfoxtrot 7767ffc
udpate function args
tangowithfoxtrot c44f52a
tweak output format
tangowithfoxtrot ef6a725
move loginaccesstoken into authclient
tangowithfoxtrot 0c9500d
Manually update PHP schemas
tangowithfoxtrot 6e9741b
Merge branch 'main' into sm-1402-review-and-update-php-sdk
tangowithfoxtrot 931d781
fix schema casing; newlines
tangowithfoxtrot efbf655
revert fully-qualified call to ClientSettings; unnecessary
tangowithfoxtrot 1810d8c
Merge branch 'main' into sm-1402-review-and-update-php-sdk
tangowithfoxtrot 31a2f8e
Merge branch 'sm/sm-1266-php-docs' into sm-1402-review-and-update-phpโฆ
tangowithfoxtrot 13acbc2
add basic sync example to readme
tangowithfoxtrot 653f47b
add state file to example
tangowithfoxtrot e5a0596
Update languages/php/README.md
tangowithfoxtrot 729eb3d
rm secretSync because git is being weird
tangowithfoxtrot 7fecc77
fix weird directory naming in remote git branch
tangowithfoxtrot e20a6b4
pr feedback; refactor auth
tangowithfoxtrot 7bc8b9c
update readme
tangowithfoxtrot 4b1f271
update example
tangowithfoxtrot 534d94b
more specific exception message
tangowithfoxtrot 5a8d730
apply grammar suggestions
tangowithfoxtrot 1ffd2d9
apply formatting suggestions
tangowithfoxtrot 64e984c
Update languages/php/README.md
tangowithfoxtrot 49b5023
[SM-1402] Automatic PHP schema generation (#1036)
mzieniukbw a57e2ed
add link to access token
tangowithfoxtrot 028c43d
update project name
tangowithfoxtrot f255347
Revert "add link to access token"
tangowithfoxtrot 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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
.DS_Store | ||
vendor | ||
src/lib/ | ||
src/Schemas/ |
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,56 @@ | ||
# PHP Installation | ||
|
||
## Introduction | ||
|
||
Composer is used to build the PHP Bitwarden client library. | ||
|
||
## Prerequisites | ||
|
||
- PHP >= 8.0 | ||
- FFI extension enabled in PHP configuration | ||
- Composer | ||
- Bitwarden SDK native library. | ||
- Expected in one of below locations, depending on the OS and architecture. | ||
The `src` is relative path to the [src](./src) directory. | ||
- Windows x86_64: `src\lib\windows-x64\bitwarden_c.dll` | ||
- Linux x86_64: `src/lib/linux-x64/libbitwarden_c.so` | ||
- macOS x86_64: `src/lib/macos-x64/libbitwarden_c.dylib` | ||
- macOS aarch64: `src/lib/macos-arm64/libbitwarden_c.dylib` | ||
- If you prefer to build the SDK yourself, see the [SDK README.md](../../README.md) for instructions. | ||
|
||
## 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 STATE_FILE="<state_file>" | ||
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,121 @@ | ||
# 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. | ||
|
||
## 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]. | ||
tangowithfoxtrot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### 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>"; | ||
tangowithfoxtrot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$state_file = "<state-file>"; | ||
$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); | ||
$bitwarden_client->auth->login_access_token($access_token, $state_file); | ||
mzieniukbw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
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" | ||
$res = $bitwarden_client->projects->create($name, $organization_id); | ||
```php | ||
$name = "PHP project"; | ||
$res = $bitwarden_client->projects->create($organization_id, $name); | ||
$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->update($organization_id, $project_id, $name); | ||
``` | ||
|
||
// 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($organization_id, $key, $value, $note, [$project_id]); | ||
$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 secrets | ||
### List all secrets | ||
|
||
```php | ||
$res = $bitwarden_client->secrets->list($organization_id); | ||
``` | ||
|
||
### Update secret | ||
|
||
```php | ||
$key = "Updated key"; | ||
$note = "Updated note"; | ||
$value = "Updated value"; | ||
$res = $bitwarden_client->secrets->update($organization_id, $secret_id, $key, $value, $note, [$project_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); | ||
### Sync secrets | ||
|
||
// delete secret | ||
$res = $bitwarden_sdk->secrets->delete([$secret_id]); | ||
```php | ||
$last_synced_date = "2024-09-01T00:00:00Z"; | ||
$res = $bitwarden_client->secrets->sync($organization_id, $last_synced_date); | ||
``` | ||
|
||
### 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/ |
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.
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.