Class OneDriveFactoryStateManager<T extends OneDrive>
- All Implemented Interfaces:
AutoCloseable
OneDrive
instances for a single authenticated user. It automatically
instantiates a new OAuth flow for first-time user authorization grants and leverages persisted refresh tokens to
vend subsequent instances.
See OneDriveFactoryStateManager.CredentialConfig
on how you can configure your own application client credentials.
This factory maintains the OneDrive instance for repeated access. While the underlying connection automatically
refreshes the tokens during the object runtime lifecycle, it is recommended to obtain this instance each time to
automatically persist the state to disk so that future consuming application instances do not have to initiate a
new OAuth flow due to stale refresh tokens. Token state can be manually persisted via saveState()
}, but
can be more easily done with levering try-with-resources:
try (OneDriveFactoryStateManager manager= OneDriveFactoryStateManager.builder() .stateFile(Paths.get("./OneDriveState.json")) .build()) { DriveFolder root = manager.getInstance().getUserDrive().getRootFolder(); // Perform operations on the root folder's contents }
While this factory is customizable through its builder, the defaults are intended to simplify configuration for a
majority of use-cases (e.g., for a desktop application). The only required attribute is defining the path to the
authentication info state file. If your use-case requires configuring the underlying OkHttpClient
instance
(e.g., configuring your own SSL cert verification, proxy, and/or connection timeouts), you can configure the client
with the provided OkHttpClientBuilder
, or alternatively with OkHttp's builder: OkHttpClient.Builder
.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
The builder for creating a newOneDriveFactoryStateManager
.static class
Defines the consuming application's client credentials. -
Method Summary
-
Method Details
-
builder
Creates a new builder. Note: Assumes that the state manager is for a personal account.- Returns:
- the builder
-
builder
Creates a new builder for the givenonedriveType
.- Parameters:
onedriveType
- the OneDrive class type- Returns:
- the builder
- See Also:
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
getInstance
Obtains an authenticatedOneDrive
instance.- Returns:
- the authenticated OneDrive instance
- Throws:
OneDriveException
- if unable to authenticate while creating a new OneDrive instance
-
saveState
Persists the authentication state.- Throws:
OneDriveException
- if unable to save the authentication information
-