Class TokenAuth
java.lang.Object
dev.jacrispys.JavaBot.api.libs.auth.TokenAuth
Grants authorization to the
AgentApi and gives access based on the token-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends ClientConnection>
Tprotected booleanauthorizeDevToken(long userId, String devToken) Clone ofauthorizeToken(long, String), but has an additional check for a "dev_auth" boolean in the DBprotected booleanauthorizeToken(long userId, String authToken) Executes a DB query for the provided userId and authToken to see if a entry existsprotected <T extends ClientConnection>
TcreateConnection(long userId, String authToken) Protected method to create a instance/connection toAgentApiprotected booleanvalidateAuth(long userId, String authToken) CallsauthorizeToken(long, String)to search the database for a token
-
Constructor Details
-
TokenAuth
-
-
Method Details
-
authorize
public static <T extends ClientConnection> T authorize(long userId, String authToken) throws AuthorizationException, InterruptedException, ExecutionException - Type Parameters:
T- generic parameter to allow any Child ofClientConnectionto be returned- Parameters:
userId- user to authenticate withauthToken- token to validate through the DataBase- Returns:
- either
DeveloperConnectionorUserConnection - Throws:
AuthorizationException- if the token in not validInterruptedException- ifClientConnection's call toJDA.awaitReady()failsExecutionException- if obtaining aSqlInstanceManager.getInstance()call fails
-
createConnection
protected <T extends ClientConnection> T createConnection(long userId, String authToken) throws AuthorizationException, InterruptedException Protected method to create a instance/connection toAgentApi- Type Parameters:
T- generic parameter to allow any Child ofClientConnectionto be returned- Parameters:
userId- user to authenticate withauthToken- token to validate through the DataBase- Returns:
- either
DeveloperConnectionorUserConnection - Throws:
AuthorizationException- if the token in not validInterruptedException- ifClientConnection's call toJDA.awaitReady()fails
-
validateAuth
CallsauthorizeToken(long, String)to search the database for a token- Parameters:
userId- user to authenticate withauthToken- token to validate through the DataBase- Returns:
- true if the token is valid, false otherwise
- Throws:
AuthorizationException- if the token in not valid
-
authorizeToken
Executes a DB query for the provided userId and authToken to see if a entry exists- Parameters:
userId- user to authenticate withauthToken- token to validate through the DataBase- Returns:
- true if the token and user exist in the DB, false otherwise
- Throws:
AuthorizationException
-
authorizeDevToken
Clone ofauthorizeToken(long, String), but has an additional check for a "dev_auth" boolean in the DB- Parameters:
userId- user to authenticate withdevToken- token to validate through the DataBase- Returns:
- true if the token and user exist in the DB along with a True value for "dev_auth", false otherwise
-