Class OAuthReceiver
java.lang.Object
com.amilesend.onedrive.connection.auth.oauth.OAuthReceiver
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
OneDriveOAuthReceiver
A customized OAuth receiver that handles the OAuth token exchange redirect by hosting a HTTP server
to capture the auth and/or error code specific to Box.net OAuth flow.
This is based on LocalServerReceiver defined in the
google-oauth-java-client library.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Open a browser at the given URL usingDesktop
if available, or alternatively output the URL toSystem.out
for command-line applications.void
close()
Closes the HTTP server resource.The path to listen for the redirect.getHost()
The host of the receiver.int
getPort()
The port of the receiver to listen on.Gets the redirect URI based on the running HTTP server resource.<T> T
start()
Starts the HTTP server to handle OAuth callbacks.void
stop()
Stops the running HTTP server.Blocks until the server receives a login result, or the server is stopped bystop()
, to return an authorization code.
-
Method Details
-
browse
Open a browser at the given URL usingDesktop
if available, or alternatively output the URL toSystem.out
for command-line applications.- Parameters:
url
- URL to browse
-
start
Starts the HTTP server to handle OAuth callbacks.- Returns:
- this OAuthReceiver instance
- Throws:
OAuthReceiverException
- if an error occurred while starting the HTTP server
-
stop
Stops the running HTTP server.- Throws:
OAuthReceiverException
- if an error occurred while stopping the server
-
close
Closes the HTTP server resource.- Specified by:
close
in interfaceAutoCloseable
- Throws:
OAuthReceiverException
- if an error occurred while closing the HTTP server resource
-
getRedirectUri
Gets the redirect URI based on the running HTTP server resource.- Returns:
- the redirect URI
-
waitForCode
Blocks until the server receives a login result, or the server is stopped bystop()
, to return an authorization code.- Returns:
- authorization code if login succeeds; may return
null
if the server is stopped byclose()
- Throws:
OAuthReceiverException
- if the server receives an error code (through an HTTP request parametererror
)
-
defaultOAuthReceiverBuilder
-
getHost
The host of the receiver. -
getCallbackPath
The path to listen for the redirect. -
getPort
public int getPort()The port of the receiver to listen on.
-