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
Modifier and TypeInterfaceDescriptionstatic class
Builder for creating OAuth2Client instances. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The 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 ofOAuth2Guilds
from theSession
.long
getId()
Gets the client ID for this OAuth2Client.Gets the client's secret.Gets the client'sSessionController
.Gets the client'sStateController
.Requests aOAuth2User
from theSession
.startSession
(String code, String state, String identifier, Scope... scopes) Starts aSession
with 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 aSession
with 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 returnnull
when provided the same state, so that this may throw aInvalidStateException
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 anull
redirect URI.
-
getUser
Requests aOAuth2User
from 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
OAuth2Action
for the OAuth2User to be retrieved.
-
getGuilds
Requests a list ofOAuth2Guilds
from 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 aMissingScopeException
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'sStateController
.- Returns:
- The client's StateController.
-
getSessionController
SessionController getSessionController()Gets the client'sSessionController
.- Returns:
- The client's SessionController.
-