Credentials

Master Credentials with WithMasterCredentials

WithMasterCredentials accepts an ICredentials built earlier, typically with CredentialServiceType.None and WithUsername and WithPassword, and copies its Username, Password, ServiceKey, ClientId, ClientSecret, ServiceAccountKeyJson, AccessToken, RefreshToken and OAuthScope into the current request.

WithService still decides which vault or service GetCredentialsFor and SaveTo query; only the authentication fields come from the supplied credentials. That saves repeating master login details across a run of GetCredentialsFor calls for different sites.

It sits on the same step as WithUsername, WithServiceKey and WithClientId, so it is reachable straight after WithService.

NOTE

There are two kinds of WithCredentials in GPAL and they point in opposite directions. A browser, a mail server, GPAL.YouTube and the AI client all take WithCredentials(ICredentials), and that hands a credential to something so it can use it. WithMasterCredentials is the other direction: it hands over the login that opens the vault, so that GetCredentialsFor can go and fetch a different credential entirely. Naming them apart is what keeps the two straight.

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 and password that WithMasterCredentials copies into each LastPass request. Either entry point works: GPAL.Credentials narrows step by step, and GPAL.CredentialsFor hands back a built object with the service already set.

// 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.Credentials

.WithService(CredentialServiceType.LastPass)

.WithMasterCredentials(masterLogin)

.GetCredentialsFor("siteA.com")

.WithDomain("siteA.com")

.SaveTo(siteAGrid);


var siteBGrid = GPAL.Grid.ToGPALObject();

GPAL.Credentials

.WithService(CredentialServiceType.LastPass)

.WithMasterCredentials(masterLogin)

.GetCredentialsFor("siteB.com")

.WithDomain("siteB.com")

.SaveTo(siteBGrid);

💬 Ask GPAL