Class OAuth2AuthenticationProvider

java.lang.Object
one.jpro.platform.auth.core.oauth2.OAuth2AuthenticationProvider
All Implemented Interfaces:
AuthenticationProvider<Credentials>
Direct Known Subclasses:
OpenIDAuthenticationProvider

public class OAuth2AuthenticationProvider extends Object implements AuthenticationProvider<Credentials>
Base class for creating an OAuth2 authentication provider.
  • Constructor Details

    • OAuth2AuthenticationProvider

      public OAuth2AuthenticationProvider(@Nullable @Nullable javafx.stage.Stage stage, @NotNull @NotNull OAuth2API api)
      Creates an OAuth2 authentication provider.
      Parameters:
      stage - the JavaFX application stage
      api - the OAuth2 api
    • OAuth2AuthenticationProvider

      public OAuth2AuthenticationProvider(@Nullable @Nullable javafx.stage.Stage stage, @NotNull @NotNull OAuth2Options options)
      Creates an OAuth2 authentication provider.
      Parameters:
      stage - the JavaFX application stage
      options - the OAuth2 options
  • Method Details

    • getOptions

      @NotNull public final @NotNull OAuth2Options getOptions()
      Returns the options used to configure this provider.
      Returns:
      an OAuth2 options object
    • authorizeUrl

      public CompletableFuture<String> authorizeUrl(@NotNull @NotNull OAuth2Credentials credentials)
      The client sends the end-user's browser to the authorization endpoint. This endpoint is where the user signs in and grants access. End-user interaction is required.
      Parameters:
      credentials - the credentials to authenticate
      Returns:
      a CompletableFuture that will complete with the authorization URL once the HTTP server is ready to handle the callback, or with an exception if an error occurs during the process.
    • authenticate

      public CompletableFuture<User> authenticate(@NotNull @NotNull Credentials credentials)
      Authenticate a user with the given credentials.
      Specified by:
      authenticate in interface AuthenticationProvider<Credentials>
      Parameters:
      credentials - the credentials to authenticate
      Returns:
      a future that will complete with the authenticated user
    • discover

      Creates a OAuth2 authentication provider for OpenID Connect Discovery. The discovery will use the given site in the configuration options and attempt to load the well-known descriptor.
      Returns:
      an OAuth2AuthenticationProvider instance.
    • introspect

      public CompletableFuture<org.json.JSONObject> introspect(User user, String tokenType)
      Determine the active state of an OAuth 2.0 token.
      Parameters:
      user - the user
      tokenType - the token type to introspect
      Returns:
      a CompletableFuture with the introspection response information in JSON format.
    • refresh

      public CompletableFuture<User> refresh(User user) throws IllegalStateException
      Refreshes the user's access token.
      Parameters:
      user - the user
      Returns:
      a new user instance with the refreshed access token
      Throws:
      IllegalStateException - if the user does not have a refresh token
    • revoke

      public CompletableFuture<Void> revoke(User user, String tokenType)
      Revokes an obtained access or refresh token. More info at RFC 7009.
      Parameters:
      user - the user to revoke
      tokenType - the token type (either access_token or refresh_token)
      Returns:
      a CompletableFuture that completes when the token is revoked.
    • userInfo

      public CompletableFuture<org.json.JSONObject> userInfo(@NotNull @NotNull User user)
      Retrieve user information and other attributes for a logged-in end-user.
      Parameters:
      user - the user (access token) to fetch the user information.
      Returns:
      a CompletableFuture with the user information in JSON format.
      See Also:
    • logout

      public CompletableFuture<Void> logout(@NotNull @NotNull User user)
      Logout the user from this OAuth2 provider.
      Parameters:
      user - the user to logout
      Returns:
      a CompletableFuture that completes when the user is logged out.