A C# Client for interacting with the PasswordSafe Service
License
—
Deps
0
Install Size
—
Vulns
✓ 0
Published
Oct 19, 2024
$ dotnet add package ModPosh.PasswordSafeClient| Latest Version | Nuget.org | Issues | 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.
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"
HttpClient and Token# 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)
Task<Credential> GetCredentialAsync(int projectId, int credentialId)
Task<Credential> CreateCredentialAsync(int projectId, CredentialRequest credentialRequest)
Task UpdateCredentialAsync(int projectId, int credentialId, CredentialRequest credentialRequest)
Task DeleteCredentialAsync(int projectId, int credentialId)