Class OAuthReceiver

java.lang.Object
com.amilesend.onedrive.connection.auth.oauth.OAuthReceiver
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
OneDriveOAuthReceiver

public class OAuthReceiver extends Object implements AutoCloseable
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.
  • Method Details

    • browse

      public static void browse(String url)
      Open a browser at the given URL using Desktop if available, or alternatively output the URL to System.out for command-line applications.
      Parameters:
      url - URL to browse
    • start

      public <T> T start() throws OAuthReceiverException
      Starts the HTTP server to handle OAuth callbacks.
      Returns:
      this OAuthReceiver instance
      Throws:
      OAuthReceiverException - if an error occurred while starting the HTTP server
    • stop

      public void stop() throws OAuthReceiverException
      Stops the running HTTP server.
      Throws:
      OAuthReceiverException - if an error occurred while stopping the server
    • close

      public void close() throws OAuthReceiverException
      Closes the HTTP server resource.
      Specified by:
      close in interface AutoCloseable
      Throws:
      OAuthReceiverException - if an error occurred while closing the HTTP server resource
    • getRedirectUri

      public String getRedirectUri()
      Gets the redirect URI based on the running HTTP server resource.
      Returns:
      the redirect URI
    • waitForCode

      public String waitForCode() throws OAuthReceiverException
      Blocks until the server receives a login result, or the server is stopped by stop(), to return an authorization code.
      Returns:
      authorization code if login succeeds; may return null if the server is stopped by close()
      Throws:
      OAuthReceiverException - if the server receives an error code (through an HTTP request parameter error)
    • defaultOAuthReceiverBuilder

      public static OAuthReceiver.OAuthReceiverBuilder defaultOAuthReceiverBuilder()
    • getHost

      public String getHost()
      The host of the receiver.
    • getCallbackPath

      public String getCallbackPath()
      The path to listen for the redirect.
    • getPort

      public int getPort()
      The port of the receiver to listen on.