Class BusinessAccountAuthManager
java.lang.Object
com.amilesend.onedrive.connection.auth.BusinessAccountAuthManager
- All Implemented Interfaces:
com.amilesend.client.connection.auth.AuthManager<OneDriveAuthInfo>
,OneDriveAuthManager
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:
Listservices = 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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
-
Field Summary
Fields inherited from interface com.amilesend.onedrive.connection.auth.OneDriveAuthManager
AUTH_CODE_BODY_ARAM, AUTH_CODE_GRANT_TYPE_BODY_PARAM_VALUE, AUTH_TOKEN_URL, CLIENT_ID_BODY_PARAM, CLIENT_SECRET_BODY_PARAM, FORM_DATA_CONTENT_TYPE, GRANT_TYPE_BODY_PARAM, REDIRECT_URI_BODY_PARAM, REFRESH_TOKEN_BODY_PARAM, REFRESH_TOKEN_GRANT_TYPE_BODY_PARAM_VALUE
-
Method Summary
Modifier and TypeMethodDescriptionvoid
authenticateService
(@NonNull Service service) Authenticates with the givenservice
and refreshes the auth tokens so that a newOneDriveConnection
can be used to access the service.Retrieves the associated endpoint to use for OneDrive operations.Fetches the list of services available to the authenticated business user.boolean
boolean
Determines if the current authentication information is expired.redeemToken
(String authCode) Issues a request to redeem the givenauthCode
in order to retrieve access and refresh tokens as aOneDriveAuthInfo
.Issues a request to refresh the auth tokens and returns the refreshed tokens as aOneDriveAuthInfo
.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.amilesend.onedrive.connection.auth.OneDriveAuthManager
addAuthentication, refreshIfExpired, refreshIfExpiredAndFetchFullToken
-
Method Details
-
isAuthenticated
public boolean isAuthenticated()- Specified by:
isAuthenticated
in interfacecom.amilesend.client.connection.auth.AuthManager<OneDriveAuthInfo>
-
isExpired
public boolean isExpired()Description copied from interface:OneDriveAuthManager
Determines if the current authentication information is expired.- Specified by:
isExpired
in interfaceOneDriveAuthManager
- Returns:
true
if expired; else,false
-
getAuthInfo
- Specified by:
getAuthInfo
in interfacecom.amilesend.client.connection.auth.AuthManager<OneDriveAuthInfo>
-
getAuthenticatedEndpoint
Description copied from interface:OneDriveAuthManager
Retrieves the associated endpoint to use for OneDrive operations.- Specified by:
getAuthenticatedEndpoint
in interfaceOneDriveAuthManager
-
redeemToken
Description copied from interface:OneDriveAuthManager
Issues a request to redeem the givenauthCode
in order to retrieve access and refresh tokens as aOneDriveAuthInfo
.- Specified by:
redeemToken
in interfaceOneDriveAuthManager
- Parameters:
authCode
- the authorization code- Returns:
- the authorization information
- See Also:
-
refreshToken
Description copied from interface:OneDriveAuthManager
Issues a request to refresh the auth tokens and returns the refreshed tokens as aOneDriveAuthInfo
.- Specified by:
refreshToken
in interfaceOneDriveAuthManager
- Returns:
- the authorization information
- See Also:
-
getServices
Fetches the list of services available to the authenticated business user. Note: Once a service is selected, you must invokeauthenticateService(Service)
prior to instantiating a new connection.- Returns:
- the list of services
-
authenticateService
Authenticates with the givenservice
and refreshes the auth tokens so that a newOneDriveConnection
can be used to access the service.- Parameters:
service
- the service to authenticate
-
builderWithAuthCode
-
builderWithAuthInfo
-
getResourceId
-