Latest Version | Nuget.org | Issues | Testing | License | Discord |
---|---|---|---|---|---|
ModPosh.PasswordSafeClient is a C# client library for interacting with the PasswordSafe API. It allows developers to manage credentials within projects by providing a simple and flexible API interface. This client supports basic operations such as retrieving, creating, updating, and deleting credentials, and it uses an authentication token to securely communicate with the API.
- Retrieve all credentials for a project.
- Retrieve a specific credential by its ID.
- Create new credentials.
- Update existing credentials.
- Delete credentials from a project.
- Supports token-based authentication (
X-Auth-Token
).
You can install ModPosh.PasswordSafeClient via NuGet:
dotnet add package ModPosh.PasswordSafeClient
Or by adding it to your csproj
file:
<PackageReference Include="ModPosh.PasswordSafeClient" Version="1.0.0" />
You need to pass an HttpClient
and an authentication token (X-Auth-Token
) to create an instance of the PasswordSafeClient
.
using ModPosh.PasswordSafeClient;
using ModPosh.PasswordSafeClient.Factory;
using System.Net.Http;
var httpClient = new HttpClient { BaseAddress = new Uri("https://pwdsafe.rackspace.net") };
httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
string authToken = "your-auth-token"; // Replace with a valid token
var passwordSafeClient = PasswordSafeClientFactory.Create(httpClient, authToken);
// Example usage: Retrieve a specific credential
int projectId = 30795;
int credentialId = 320223;
var credential = await passwordSafeClient.CredentialsService.GetCredentialAsync(projectId, credentialId);
Console.WriteLine($"Credential Description: {credential.Description}");
You can also use ModPosh.PasswordSafeClient in PowerShell by importing it into your script.
Add-Type -Path "path\to\ModPosh.PasswordSafeClient.dll"
# Create an instance of HttpClient
$httpClient = [System.Net.Http.HttpClient]::new()
$httpClient.BaseAddress = [Uri]::new("https://pwdsafe.rackspace.net")
$httpClient.DefaultRequestHeaders.Add("Accept", "application/json")
# Set your authentication token
$authToken = "your-auth-token" # Replace with the actual token
# Create the PasswordSafeClient
$passwordSafeClient = [ModPosh.PasswordSafeClient.Factory.PasswordSafeClientFactory]::Create($httpClient, $authToken)
# Set the project and credential IDs
$projectId = 30795 # Replace with your project ID
$credentialId = 320223 # Replace with your credential ID
# Retrieve the credential
$credential = $passwordSafeClient.CredentialsService.GetCredentialAsync($projectId, $credentialId).GetAwaiter().GetResult()
# Output the credential information
$credential | ConvertTo-Json -Depth 5
-
Task<List<Credential>> GetAllCredentialsAsync(int projectId)
- Retrieves all credentials for a specific project.
-
Task<Credential> GetCredentialAsync(int projectId, int credentialId)
- Retrieves a specific credential by its ID.
-
Task<Credential> CreateCredentialAsync(int projectId, CredentialRequest credentialRequest)
- Creates a new credential for the project.
-
Task UpdateCredentialAsync(int projectId, int credentialId, CredentialRequest credentialRequest)
- Updates an existing credential.
-
Task DeleteCredentialAsync(int projectId, int credentialId)
- Deletes a credential from the project.