Skip to content

Commit

Permalink
refactor bitwarden settings class
Browse files Browse the repository at this point in the history
  • Loading branch information
milost77 committed Nov 28, 2023
1 parent d9fbaa7 commit 2b5ae7c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
13 changes: 6 additions & 7 deletions languages/php/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,20 @@ be authorized by calling the access_token_login method passing your Bitwarden ac


```php
$api_url = "";
$identity_url = "";
$client_settings = new \Bitwarden\Sdk\BitwardenSettings();
$access_token = '<your token here>';
$api_url = "<api url>";
$identity_url = "<identity url>";
$bitwarden_settings = new \Bitwarden\Sdk\BitwardenSettings($api_url, $identity_url);

$bitwarden_client = new \Bitwarden\Sdk\BitwardenClient($client_settings);
$bitwarden_client = new \Bitwarden\Sdk\BitwardenClient($bitwarden_settings);
$res = $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>";

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

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

// create project
Expand Down
13 changes: 4 additions & 9 deletions languages/php/src/BitwardenSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,21 @@ class BitwardenSettings

private string $user_agent = "Bitwarden PHP SDK";

private string $device_type;
// 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;
$this->api_url = 'https://api.bitwarden.com';
}

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

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

public function get_api_url(): string
Expand Down

0 comments on commit 2b5ae7c

Please sign in to comment.