Class BusinessAccountAuthManager

java.lang.Object
com.amilesend.onedrive.connection.auth.BusinessAccountAuthManager
All Implemented Interfaces:
AuthManager

public class BusinessAccountAuthManager extends Object implements AuthManager
Manager that is responsible for obtaining and refreshing tokens to interact with a business OneDrive account for a specific resource. Note: This does not manage the initial stages of the OAUTH request flow and instead relies on a provided auth code or a pre-existing refresh token.

Example initializing with an auth code:

 BusinessAccountAuthManager authManager = BusinessAccountAuthManager.builderWithAuthCode()
         .httpClient(client) // the OKHttpClient instance
         .gsonFactory(gsonFactory) // preconfigured Gson instances
         .clientId(clientId) // the client ID of your application
         .clientSecret(clientSecret) // the client secret of your application
         .redirectUrl(redirectUrl) // the redirect URL for OAUTH flow
         .resourceId(resourceId) // the specific resource identifier
         .authCode(authCode) // The obtained auth code from initial OAUTH handshake
         .buildWithAuthCode();
 

Once the BusinessAccountAuthManager is created, the next step is to discover available services to connect to and authorize access to a chosen service:

 List services = authManager.getServices();
 authManager.authorizeService(services.get(0));
 

Example initializing with an AuthInfo (pre-existing refresh token):

 BusinessAccountAuthManager authManager = BusinessAccountAuthManager.builderWithAuthInfo()
         .httpClient(client)
         .gsonFactory(gsonFactory)
         .clientId(clientId)
         .clientSecret(clientSecret)
         .redirectUrl(redirectUrl)
         .resourceId(resourceId) // the specific resource identifier
         .authInfo(authInfo) // Instead of an auth code, an AuthInfo object is used to obtain the refresh token
         .buildWithAuthInfo();
 
Note: Existing persisted authInfo is only valid for a single resource. If the user is to access a different resource than the one that that is persisted with the auth tokens, then new access tokens are required and should invoke the builderWithAuthCode() flow.
See Also:
  • Method Details

    • isAuthenticated

      public boolean isAuthenticated()
      Description copied from interface: AuthManager
      Determines if the current authentication information is up-to-date.
      Specified by:
      isAuthenticated in interface AuthManager
      Returns:
      true if authenticated; else, false
    • isExpired

      public boolean isExpired()
      Description copied from interface: AuthManager
      Determines if the current authentication information is expired.
      Specified by:
      isExpired in interface AuthManager
      Returns:
      true if expired; else, false
    • getAuthInfo

      public AuthInfo getAuthInfo()
      Description copied from interface: AuthManager
      Retrieves the current authentication info.
      Specified by:
      getAuthInfo in interface AuthManager
      Returns:
      the authentication info
      See Also:
    • getAuthenticatedEndpoint

      public String getAuthenticatedEndpoint()
      Description copied from interface: AuthManager
      Retrieves the associated endpoint to use for OneDrive operations.
      Specified by:
      getAuthenticatedEndpoint in interface AuthManager
    • redeemToken

      public AuthInfo redeemToken(String authCode)
      Description copied from interface: AuthManager
      Issues a request to redeem the given authCode in order to retrieve access and refresh tokens as a AuthInfo.
      Specified by:
      redeemToken in interface AuthManager
      Parameters:
      authCode - the authorization code
      Returns:
      the authorization information
      See Also:
    • refreshToken

      public AuthInfo refreshToken()
      Description copied from interface: AuthManager
      Issues a request to refresh the auth tokens and returns the refreshed tokens as a AuthInfo.
      Specified by:
      refreshToken in interface AuthManager
      Returns:
      the authorization information
      See Also:
    • getServices

      public List<Service> getServices()
      Fetches the list of services available to the authenticated business user. Note: Once a service is selected, you must invoke authenticateService(Service) prior to instantiating a new connection.
      Returns:
      the list of services
    • authenticateService

      public void authenticateService(@NonNull Service service)
      Authenticates with the given service and refreshes the auth tokens so that a new OneDriveConnection can be used to access the service.
      Parameters:
      service - the service to authenticate
    • builderWithAuthCode

      public static BusinessAccountAuthManager.BuilderWithAuthCode builderWithAuthCode()
    • builderWithAuthInfo

      public static BusinessAccountAuthManager.BuilderWithAuthInfo builderWithAuthInfo()
    • getResourceId

      public String getResourceId()