Credentials

Credentials Configuration (CredentialsConfig)

Every GPAL.Credentials object loads a CredentialsConfig automatically via its Config property. CredentialsConfig.Load() reads ./credentialsConfig.json if it exists, falling back to built-in defaults for Google, Azure, AWS, and Bitwarden endpoints, OAuth redirect URIs, and the form field names used when building token requests. Call Save() after changing values to persist them for future runs. Both Load() and Save() accept an optional GPALFile: pass one to redirect to a different path, and that path becomes the new in-session default so subsequent no-arg calls use it automatically. One value in here has to agree with something outside GPAL: GoogleRestRedirectUri is where the OAuth redirect lands, so it has to be the URI registered with the provider. WithAuthRedirectUrl sets it on the credential itself, which runs after the file is loaded and therefore wins over it, so a workflow can say in its own code what it has to match rather than leaving it in a json file beside the exe.

NOTE

CredentialsConfig.UseRestRedirect (default true) controls how OAuth authorization codes are obtained: when true, GPAL polls GPALRESTAPI's get-access-token endpoint after the redirect; when false, the user is prompted to paste the authorization code manually.

WARNING

The authority of GoogleRestRedirectUri is where GPAL listens for the token, or where it expects to find a GPALRestAPI already listening. GPAL will not move to another port when that one is taken, because a redirect the provider never agreed to would not arrive. Change the port here and you change it in the provider console too, or the flow stops working.

Examples

GPAL Fluent: High-level fluent C# API

//CredentialsConfig.Load() and Save() default to ./credentialsConfig.json. Pass a GPALFile to either call to redirect to a custom path -- that path becomes the session default for all subsequent no-arg calls in the same run. WithAuthRedirectUrl writes the same GoogleRestRedirectUri value on that one credential, so the address the token has to land on is visible in the workflow that depends on it.

// Load from default path, modify, and save back

var config = CredentialsConfig.Load();

config.BitwardenAuthBase = "https://identity.bitwarden.eu";

config.BitwardenVaultBase = "https://api.bitwarden.eu";

CredentialsConfig.Save();


// Load from a custom path -- sets the session default

config = CredentialsConfig.Load(

(GPALFile)"config/creds.json");

config.GoogleRestRedirectUri = "http://localhost:3000/access-token";

CredentialsConfig.Save(); // config/creds.json

CredentialsConfig.Save(); // still config/creds.json


// Or set it on the credential, which runs after the file loads and wins over it

ICredentials google = GPAL.CredentialsFor(CredentialServiceType.Google);


google.WithAuthRedirectUrl("http://localhost:3117/access-token");

google.WithServiceKey("client-id:client-secret");


// Subsequent Credentials objects pick up the saved config automatically

var bwGrid = GPAL.Grid.ToGPALObject();

ICredentials bitwarden = GPAL.CredentialsFor(CredentialServiceType.Bitwarden);


bitwarden.WithServiceKey("client-id:client-secret");

bitwarden.WithUsername("you@example.com");


bitwarden.WithPassword("master-password");


bitwarden

.GetCredentialsFor("example.com")

.SaveTo(bwGrid);

💬 Ask GPAL