Class OneDriveFactoryStateManager<T extends OneDrive>

java.lang.Object
com.amilesend.onedrive.OneDriveFactoryStateManager<T>
All Implemented Interfaces:
AutoCloseable

public class OneDriveFactoryStateManager<T extends OneDrive> extends Object implements AutoCloseable
A factory that vends authenticated 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.