Interface OAuth2Client

All Known Implementing Classes:
OAuth2ClientImpl

public interface OAuth2Client
The central controller for OAuth2 state and session management using the Discord API.

OAuth2Client's are made using a OAuth2Client.Builder, and sessions can be appended using startSession(String, String, String, Scope...).

Author:
John Grosh ([email protected]), Kaidan Gustave
  • Field Details

    • DISCORD_REST_VERSION

      static final int DISCORD_REST_VERSION
      The REST version targeted by JDA-Utilities OAuth2.
      See Also:
  • Method Details

    • generateAuthorizationURL

      String generateAuthorizationURL(String redirectUri, Scope... scopes)
      Generates a formatted authorization URL from the provided redirect URI fragment and Scopes.
      Parameters:
      redirectUri - The redirect URI.
      scopes - The provided scopes.
      Returns:
      The generated authorization URL.
    • startSession

      @CheckReturnValue OAuth2Action<Session> startSession(String code, String state, String identifier, Scope... scopes) throws InvalidStateException
      Starts a Session with the provided code, state, and identifier. The state provided should be unique and provided through an implementation of StateController.

      If the state has already been consumed by the StateController using StateController#consumeState, then it should return null when provided the same state, so that this may throw a InvalidStateException to signify it has been consumed.

      Parameters:
      code - The code for the Session to start.
      state - The state for the Session to start.
      identifier - The identifier for the Session to start.
      scopes - The provided scopes.
      Returns:
      A OAuth2Action for the Session to start.
      Throws:
      InvalidStateException - If the state, when consumed by this client's StateController, results in a null redirect URI.
    • getUser

      @CheckReturnValue OAuth2Action<OAuth2User> getUser(Session session)
      Requests a OAuth2User from the Session.

      All Sessions should handle an individual Discord User, and as such this method retrieves data on that User when the session is provided.

      Parameters:
      session - The Session to get a OAuth2User for.
      Returns:
      A OAuth2Action for the OAuth2User to be retrieved.
    • getGuilds

      @CheckReturnValue OAuth2Action<List<OAuth2Guild>> getGuilds(Session session)
      Requests a list of OAuth2Guilds from the Session.

      All Sessions should handle an individual Discord User, and as such this method retrieves data on all the various Discord Guilds that user is a part of when the session is provided.

      Note that this can only be performed for Sessions who have the necessary 'guilds' scope.
      Trying to call this using a Session without the scope will cause a MissingScopeException to be thrown.

      Parameters:
      session - The Session to get OAuth2Guilds for.
      Returns:
      A OAuth2Action for the OAuth2Guilds to be retrieved.
      Throws:
      MissingScopeException - If the provided Session does not have the 'guilds' scope.
    • getId

      long getId()
      Gets the client ID for this OAuth2Client.
      Returns:
      The client ID.
    • getSecret

      String getSecret()
      Gets the client's secret.
      Returns:
      The client's secret.
    • getStateController

      StateController getStateController()
      Gets the client's StateController.
      Returns:
      The client's StateController.
    • getSessionController

      SessionController getSessionController()
      Gets the client's SessionController.
      Returns:
      The client's SessionController.