Record Class GmailCredentials
java.lang.Object
java.lang.Record
uno.anahata.asi.yam.tools.gmail.GmailCredentials
- Record Components:
clientId- The Google Cloud OAuth 2.0 Client ID.clientSecret- The Google Cloud OAuth 2.0 Client Secret.refreshToken- The long-lived refresh token obtained after browser authorization.emailAddress- The primary Gmail address authorized by this session.
public record GmailCredentials(String clientId, String clientSecret, String refreshToken, String emailAddress)
extends Record
Encapsulates Google OAuth 2.0 credentials and metadata for the Gmail API.
Manages loading and persisting client ID, client secret, long-lived refresh token,
and the authorized user email address in ~/.anahata/asi/gmail/credentials.json.
Also supports importing client credentials from official Google Cloud Console secrets JSON.
- Author:
- anahata
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final StringThe field for theclientIdrecord component.private final StringThe field for theclientSecretrecord component.private final StringThe field for theemailAddressrecord component.private static final com.fasterxml.jackson.databind.ObjectMapperShared JSON object mapper configured for formatted indentation and lenient property parsing.private final StringThe field for therefreshTokenrecord component. -
Constructor Summary
ConstructorsConstructorDescriptionGmailCredentials(String clientId, String clientSecret, String refreshToken, String emailAddress) Creates an instance of aGmailCredentialsrecord class. -
Method Summary
Modifier and TypeMethodDescriptionclientId()Returns the value of theclientIdrecord component.Returns the value of theclientSecretrecord component.Returns the value of theemailAddressrecord component.final booleanIndicates whether some other object is "equal to" this one.static booleanexists()Checks if a credentials file exists in either canonical or fallback paths.static GmailCredentialsfromClientSecrets(Path clientSecretsPath) Parses client ID and client secret from a Google Cloud Console credentials JSON file.static PathResolves the canonical credentials file path:~/.anahata/asi/gmail/credentials.json.booleanChecks if client ID and client secret are configured.final inthashCode()Returns a hash code value for this object.booleanChecks if a refresh token is stored and ready for autonomous API access.static GmailCredentialsload()Loads the stored Gmail credentials from disk.Returns the value of therefreshTokenrecord component.static PathResolves the active credentials path, checking canonical and fallback locations.voidsave()Persists these credentials to the canonical storage location:~/.anahata/asi/gmail/credentials.json.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
clientId
-
clientSecret
The field for theclientSecretrecord component. -
refreshToken
The field for therefreshTokenrecord component. -
emailAddress
The field for theemailAddressrecord component. -
MAPPER
private static final com.fasterxml.jackson.databind.ObjectMapper MAPPERShared JSON object mapper configured for formatted indentation and lenient property parsing.
-
-
Constructor Details
-
GmailCredentials
public GmailCredentials(String clientId, String clientSecret, String refreshToken, String emailAddress) Creates an instance of aGmailCredentialsrecord class.- Parameters:
clientId- the value for theclientIdrecord componentclientSecret- the value for theclientSecretrecord componentrefreshToken- the value for therefreshTokenrecord componentemailAddress- the value for theemailAddressrecord component
-
-
Method Details
-
getCredentialsPath
Resolves the canonical credentials file path:~/.anahata/asi/gmail/credentials.json.- Returns:
- The canonical Path to the Gmail credentials file.
-
resolveExistingCredentialsPath
Resolves the active credentials path, checking canonical and fallback locations.- Returns:
- The Path to an existing credentials file, or canonical path if none exist.
-
exists
public static boolean exists()Checks if a credentials file exists in either canonical or fallback paths.- Returns:
trueif credentials exist on disk.
-
load
Loads the stored Gmail credentials from disk.- Returns:
- The loaded
GmailCredentials. - Throws:
IOException- If the credentials file cannot be found or read.
-
fromClientSecrets
Parses client ID and client secret from a Google Cloud Console credentials JSON file.Supports standard Google formats including
installed(Desktop app),web(Web app), or flat JSON representations.- Parameters:
clientSecretsPath- The path to the client secrets JSON file.- Returns:
- A
GmailCredentialsinstance containing parsed client secrets. - Throws:
IOException- If file reading or JSON parsing fails.
-
save
Persists these credentials to the canonical storage location:~/.anahata/asi/gmail/credentials.json.- Throws:
IOException- If writing to disk fails.
-
hasClientSecrets
public boolean hasClientSecrets()Checks if client ID and client secret are configured.- Returns:
trueif OAuth client details are present.
-
isAuthenticated
public boolean isAuthenticated()Checks if a refresh token is stored and ready for autonomous API access.- Returns:
trueif authenticated with a refresh token.
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
clientId
-
clientSecret
Returns the value of theclientSecretrecord component.- Returns:
- the value of the
clientSecretrecord component
-
refreshToken
Returns the value of therefreshTokenrecord component.- Returns:
- the value of the
refreshTokenrecord component
-
emailAddress
Returns the value of theemailAddressrecord component.- Returns:
- the value of the
emailAddressrecord component
-

