Skip to content

Commit

Permalink
add bitwarden settings
Browse files Browse the repository at this point in the history
  • Loading branch information
milost77 committed Nov 27, 2023
1 parent bd0433b commit d9fbaa7
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 395 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ crates/bitwarden-napi/sdk-napi.*.node
# Complied TypeScript client
crates/bitwarden-napi/dist

# PHP
languages/php/vendor

# Uniffi
languages/swift/BitwardenFFI.xcframework
languages/swift/tmp
Expand Down
23 changes: 12 additions & 11 deletions languages/php/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@ If you are not using the standalone version of this library, file will be placed
## Usage

To interact with the client first you need to obtain the access token from Bitwarden.
You can initialize ClientSettings and its setting before passing it to the BitwardenClient.
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.

```php
$client_settings = new \Bitwarden\Sdk\Schemas\ClientSettings()
$client_settings->apiUrl = getenv('API_URL') ?: 'https://api.bitwarden.com';
$client_settings->identityUrl = getenv('IDENTITY_URL') ?: 'https://identity.bitwarden.com';
$client_settings->userAgent = getenv('USER_AGENT') ?: 'SDK';
$client_settings->deviceType = getenv('DEVICE_TYPE') ?: 'SDK';
```
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.

Authorization can be performed using access token like so:

```php
$access_token = '<you access token here>';
$api_url = "";
$identity_url = "";
$client_settings = new \Bitwarden\Sdk\BitwardenSettings();

$bitwarden_client = new \Bitwarden\Sdk\BitwardenClient($client_settings);
$result = $bitwarden_client->access_token_login($access_token);
$res = $bitwarden_client->access_token_login($access_token);
```

After successful authorization you can interact with client to manage your projects and secrets.
Expand Down
2 changes: 1 addition & 1 deletion languages/php/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$access_token = '<you access token here>';
$organization_id = "<your organization id here>";

$client_settings = new \Bitwarden\Sdk\Schemas\ClientSettings();
$client_settings = new \Bitwarden\Sdk\BitwardenSettings();

$bitwarden_client = new \Bitwarden\Sdk\BitwardenClient($client_settings);
$res = $bitwarden_client->access_token_login($access_token);
Expand Down
6 changes: 4 additions & 2 deletions languages/php/src/BitwardenClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ class BitwardenClient

private FFI\CData $handle;

public function __construct(ClientSettings $clientSettings)
public function __construct(BitwardenSettings $bitwardenSettings)
{
$this->clientSettings = $clientSettings;
$this->clientSettings = new ClientSettings();
$this->clientSettings->apiUrl = $bitwardenSettings->get_api_url();
$this->clientSettings->identityUrl = $bitwardenSettings->get_identity_url();

$this->bitwarden_lib = new BitwardenLib();
$this->handle = $this->bitwarden_lib->init($this->clientSettings);
Expand Down
54 changes: 54 additions & 0 deletions languages/php/src/BitwardenSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Bitwarden\Sdk;

class BitwardenSettings
{
private string $api_url;

private string $identity_url;

private string $user_agent = "Bitwarden PHP SDK";

private string $device_type;

public function __construct($api_url = null, $identity_url = null, $device_type = null)
{
if (is_null($api_url))
{
$this->api_url = getenv('API_URL') ?: 'https://api.bitwarden.com';
$this->identity_url = getenv('IDENTITY_URL') ?: 'https://identity.bitwarden.com';
} else {
$this->api_url = $api_url;
}

if (is_null($identity_url))
{
$this->identity_url = getenv('IDENTITY_URL') ?: 'https://identity.bitwarden.com';
} else {
$this->identity_url = $identity_url;
}

$this->device_type = $device_type ? isset($device_type) : "";
}

public function get_api_url(): string
{
return $this->api_url;
}

public function get_identity_url(): string
{
return $this->identity_url;
}

public function get_user_agent(): string
{
return $this->user_agent;
}

public function get_device_type(): string
{
return $this->device_type;
}
}
51 changes: 0 additions & 51 deletions languages/php/src/schemas/ApiKeyLoginRequest.php

This file was deleted.

43 changes: 0 additions & 43 deletions languages/php/src/schemas/FingerprintRequest.php

This file was deleted.

32 changes: 0 additions & 32 deletions languages/php/src/schemas/Kdf.php

This file was deleted.

48 changes: 0 additions & 48 deletions languages/php/src/schemas/KdfArgon2id.php

This file was deleted.

34 changes: 0 additions & 34 deletions languages/php/src/schemas/KdfPBKDF2.php

This file was deleted.

60 changes: 0 additions & 60 deletions languages/php/src/schemas/PasswordLoginRequest.php

This file was deleted.

Loading

0 comments on commit d9fbaa7

Please sign in to comment.