Class OAuth2ClientImpl
- All Implemented Interfaces:
OAuth2Client
- Author:
- John Grosh ([email protected])
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.jagrosh.jdautilities.oauth2.OAuth2Client
OAuth2Client.Builder
-
Field Summary
Fields inherited from interface com.jagrosh.jdautilities.oauth2.OAuth2Client
DISCORD_REST_VERSION
-
Constructor Summary
ConstructorDescriptionOAuth2ClientImpl
(long clientId, String clientSecret, SessionController sessionController, StateController stateController, okhttp3.OkHttpClient httpClient) -
Method Summary
Modifier and TypeMethodDescriptionprotected static net.dv8tion.jda.api.exceptions.HttpException
failure
(okhttp3.Response response) generateAuthorizationURL
(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 internal OAuth2Requester used by this OAuth2Client.Gets the client's secret.Gets the client'sSessionController
.Gets the client'sStateController
.Requests aOAuth2User
from theSession
.void
shutdown()
startSession
(String code, String state, String identifier, Scope... scopes) Starts aSession
with the provided code, state, and identifier.
-
Constructor Details
-
OAuth2ClientImpl
public OAuth2ClientImpl(long clientId, String clientSecret, SessionController sessionController, StateController stateController, okhttp3.OkHttpClient httpClient)
-
-
Method Details
-
generateAuthorizationURL
Description copied from interface:OAuth2Client
Generates a formatted authorization URL from the provided redirect URI fragment andScopes
.- Specified by:
generateAuthorizationURL
in interfaceOAuth2Client
- 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 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.- Specified by:
startSession
in interfaceOAuth2Client
- 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
Description copied from interface:OAuth2Client
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.
- Specified by:
getUser
in interfaceOAuth2Client
- Parameters:
session
- The Session to get a OAuth2User for.- Returns:
- A
OAuth2Action
for the OAuth2User to be retrieved.
-
getGuilds
Description copied from interface:OAuth2Client
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.- Specified by:
getGuilds
in interfaceOAuth2Client
- 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 interfaceOAuth2Client
- Returns:
- The client ID.
-
getSecret
Description copied from interface:OAuth2Client
Gets the client's secret.- Specified by:
getSecret
in interfaceOAuth2Client
- Returns:
- The client's secret.
-
getStateController
Description copied from interface:OAuth2Client
Gets the client'sStateController
.- Specified by:
getStateController
in interfaceOAuth2Client
- Returns:
- The client's StateController.
-
getSessionController
Description copied from interface:OAuth2Client
Gets the client'sSessionController
.- Specified by:
getSessionController
in interfaceOAuth2Client
- Returns:
- The client's SessionController.
-
shutdown
public void shutdown() -
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
-