Class OAuthReceiver

java.lang.Object
com.amilesend.discogs.connection.auth.oauth.OAuthReceiver
All Implemented Interfaces:
AutoCloseable

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

    • start

      public void start()
      Starts the HTTP server to handle OAuth callbacks.
      Throws:
      OAuthReceiverException - if an error occurred while starting the HTTP server
    • stop

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

      public void close()
      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()
      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)
    • builder

      public static OAuthReceiver.OAuthReceiverBuilder builder()
    • 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.