Interface OAuth2Client
- All Known Implementing Classes:
OAuth2ClientImpl
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
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classBuilder for creating OAuth2Client instances. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe REST version targeted by JDA-Utilities OAuth2. -
Method Summary
Modifier and TypeMethodDescriptiongenerateAuthorizationURL(String redirectUri, Scope... scopes) Generates a formatted authorization URL from the provided redirect URI fragment andScopes.Requests a list ofOAuth2Guildsfrom theSession.longgetId()Gets the client ID for this OAuth2Client.Gets the client's secret.Gets the client'sSessionController.Gets the client'sStateController.Requests aOAuth2Userfrom theSession.startSession(String code, String state, String identifier, Scope... scopes) Starts aSessionwith the provided code, state, and identifier.
-
Field Details
-
DISCORD_REST_VERSION
static final int DISCORD_REST_VERSIONThe REST version targeted by JDA-Utilities OAuth2.- See Also:
-
-
Method Details
-
generateAuthorizationURL
Generates a formatted authorization URL from the provided redirect URI fragment andScopes.- 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 aSessionwith the provided code, state, and identifier. The state provided should be unique and provided through an implementation ofStateController.If the state has already been consumed by the StateController using
StateController#consumeState, then it should returnnullwhen provided the same state, so that this may throw aInvalidStateExceptionto 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
OAuth2Actionfor the Session to start. - Throws:
InvalidStateException- If the state, when consumed by this client's StateController, results in anullredirect URI.
-
getUser
Requests aOAuth2Userfrom theSession.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
OAuth2Actionfor the OAuth2User to be retrieved.
-
getGuilds
Requests a list ofOAuth2Guildsfrom theSession.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 aMissingScopeExceptionto be thrown.- Parameters:
session- The Session to get OAuth2Guilds for.- Returns:
- A
OAuth2Actionfor 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'sStateController.- Returns:
- The client's StateController.
-
getSessionController
SessionController getSessionController()Gets the client'sSessionController.- Returns:
- The client's SessionController.
-