Credentials

Master Credentials with WithCredentials

WithCredentials(ICredentials) copies authentication fields - username, password, service key, OAuth tokens - from a previously-built credentials object, so a password manager's master login can be built once and reused across many lookups.

WithCredentials(ICredentials) copies authentication fields - username, password, service key, OAuth tokens - from a previously-built credentials object, so a password manager's master login can be built once and reused across many lookups.

WithCredentials accepts an ICredentials built earlier (typically with CredentialServiceType.None and WithUsername/WithPassword) and copies its Username, Password, ServiceKey, ClientId, ClientSecret, ServiceAccountKeyJson, AccessToken, RefreshToken, and OAuthScope into the current request. WithService still determines which vault or service GetCredentialsFor/SaveTo queries - only the authentication fields come from the supplied credentials. This avoids repeating master login details across multiple GetCredentialsFor calls for different sites.

Examples

GPAL Fluent: High-level fluent C# API

//masterLogin is built once with CredentialServiceType.None and never queries a vault itself - it exists only to carry the Username/Password that WithCredentials copies into each subsequent LastPass request.

// Build a reusable master login for your password manager account var masterLogin = GPAL.CredentialsFor(CredentialServiceType.None) .WithUsername("you@example.com") .WithPassword("master-password") .ToGPALObject(); // Reuse it across multiple vault lookups var siteAGrid = GPAL.Grid.ToGPALObject(); GPAL.CredentialsFor(CredentialServiceType.LastPass) .WithCredentials(masterLogin) .GetCredentialsFor("siteA.com") .WithDomain("siteA.com") .SaveTo(siteAGrid); var siteBGrid = GPAL.Grid.ToGPALObject(); GPAL.CredentialsFor(CredentialServiceType.LastPass) .WithCredentials(masterLogin) .GetCredentialsFor("siteB.com") .WithDomain("siteB.com") .SaveTo(siteBGrid);