Package io.github.mastodonContentMover
Class OAuthListener
java.lang.Object
io.github.mastodonContentMover.OAuthListener
Operates a minimal HTTP server on the local machine for the duration of OAuth
authorization of the tool by a Mastodon instance, passing the callback code
collected via an OAuth callback (from a browser on that machine) to the instantiated
The HTTP server is then shut down and the code is used by the
By default, the HTTP server is bound to port 8081 (this is specified within
Uses the singleton model, as only one
Also defines inner class
Authenticator
singletone object.
The HTTP server is then shut down and the code is used by the
Authenticator
to obtain an access token that grants access to user-level API methods on the
Mastodon instance.
By default, the HTTP server is bound to port 8081 (this is specified within
Authenticator
)
but can be bound to a different port as needed. If a custom port is used, credentials
are not saved.
Uses the singleton model, as only one
OAuthListener
should be instantiated at a time. Synchronized methods will be synchronized on the
singleton object (because there is only ever one).
Also defines inner class
OAuthListener.OAuthRequestHandler
that implements the HttpHandler
interface to handle
inbound HTTP requests in a separate thread. It is within this inner class that the
HTML to be displayed in the browser after OAuth authorization is defined.
- Since:
- 0.01.00
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionprotected static OAuthListener
getInstance
(int port) Obtains a reference to the currently instantiatedOAuthListener
singleton object, or instantiates one if that has not already been done using the port specified.protected void
shutdown()
Halts the HTTP server, allowing some time for the shutdown process to complete and then releasing resources that had been allocated to it.
-
Method Details
-
getInstance
Obtains a reference to the currently instantiatedOAuthListener
singleton object, or instantiates one if that has not already been done using the port specified.
If the currently instantiated singleton is bound to a port different to the one specified, it is shutdown and restarted on the specified port.- Parameters:
port
- the TCP port on the local machine on which to bind the singletonOAuthListener
- Returns:
- a singleton instance of
OAuthListener
bound to the port specified - Throws:
IOException
- (TODO: add more info here on when this happens)- Since:
- 0.01.00
-
shutdown
protected void shutdown()Halts the HTTP server, allowing some time for the shutdown process to complete and then releasing resources that had been allocated to it.- Since:
- 0.01.00
-