Class OAuth2ClientImpl

java.lang.Object
com.jagrosh.jdautilities.oauth2.entities.impl.OAuth2ClientImpl
All Implemented Interfaces:
OAuth2Client

public class OAuth2ClientImpl extends Object implements OAuth2Client
Author:
John Grosh ([email protected])
  • Constructor Details

  • Method Details

    • generateAuthorizationURL

      public String generateAuthorizationURL(String redirectUri, Scope... scopes)
      Description copied from interface: OAuth2Client
      Generates a formatted authorization URL from the provided redirect URI fragment and Scopes.
      Specified by:
      generateAuthorizationURL in interface OAuth2Client
      Parameters:
      redirectUri - The redirect URI.
      scopes - The provided scopes.
      Returns:
      The generated authorization URL.
    • startSession

      public OAuth2Action<Session> startSession(String code, String state, String identifier, Scope... scopes) throws InvalidStateException
      Description copied from interface: OAuth2Client
      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.

      Specified by:
      startSession in interface OAuth2Client
      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

      public OAuth2Action<OAuth2User> getUser(Session session)
      Description copied from interface: OAuth2Client
      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.

      Specified by:
      getUser in interface OAuth2Client
      Parameters:
      session - The Session to get a OAuth2User for.
      Returns:
      A OAuth2Action for the OAuth2User to be retrieved.
    • getGuilds

      public OAuth2Action<List<OAuth2Guild>> getGuilds(Session session)
      Description copied from interface: OAuth2Client
      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.

      Specified by:
      getGuilds in interface OAuth2Client
      Parameters:
      session - The Session to get OAuth2Guilds for.
      Returns:
      A OAuth2Action for the OAuth2Guilds to be retrieved.
    • getId

      public long getId()
      Description copied from interface: OAuth2Client
      Gets the client ID for this OAuth2Client.
      Specified by:
      getId in interface OAuth2Client
      Returns:
      The client ID.
    • getSecret

      public String getSecret()
      Description copied from interface: OAuth2Client
      Gets the client's secret.
      Specified by:
      getSecret in interface OAuth2Client
      Returns:
      The client's secret.
    • getStateController

      public StateController getStateController()
      Description copied from interface: OAuth2Client
      Gets the client's StateController.
      Specified by:
      getStateController in interface OAuth2Client
      Returns:
      The client's StateController.
    • getSessionController

      public SessionController getSessionController()
      Description copied from interface: OAuth2Client
      Gets the client's SessionController.
      Specified by:
      getSessionController in interface OAuth2Client
      Returns:
      The client's SessionController.
    • shutdown

      public void shutdown()
    • getRequester

      public OAuth2Requester getRequester()
      Gets the internal OAuth2Requester used by this OAuth2Client.
      Returns:
      The internal OAuth2Requester used by this OAuth2Client.
    • failure

      protected static net.dv8tion.jda.api.exceptions.HttpException failure(okhttp3.Response response) throws IOException
      Throws:
      IOException