Search in sources :

Example 1 with VerifyJson

use of com.xtaolabs.gcauth_oauth.json.VerifyJson in project GCAuth-OAuth by Xtao-Team.

the class VerifyHandler method handle.

public static void handle(Request req, Response res) {
    VerifyJson request = req.body(VerifyJson.class);
    LoginResultJson responseData = new LoginResultJson();
    DecodedJWT jwt = parse.deToken(request.access_token);
    Account account = null;
    if (jwt != null) {
        account = Authentication.getAccountByOneTimeToken(jwt.getClaim("token").asString());
    }
    // Login
    if (account == null) {
        Grasscutter.getLogger().info("[GCAuth] Client " + req.ip() + " failed to log in");
        responseData.retcode = -201;
        responseData.message = "Token is invalid";
        res.send(responseData);
        return;
    }
    // Account was found, log the player in
    responseData.message = "OK";
    responseData.data.account.uid = account.getId();
    responseData.data.account.token = account.generateSessionKey();
    responseData.data.account.email = account.getEmail();
    responseData.data.account.twitter_name = account.getUsername();
    Grasscutter.getLogger().info(String.format("[GCAuth] Client %s logged in as %s", req.ip(), responseData.data.account.uid));
    res.send(responseData);
}
Also used : LoginResultJson(emu.grasscutter.server.http.objects.LoginResultJson) Account(emu.grasscutter.game.Account) VerifyJson(com.xtaolabs.gcauth_oauth.json.VerifyJson) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT)

Aggregations

DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)1 VerifyJson (com.xtaolabs.gcauth_oauth.json.VerifyJson)1 Account (emu.grasscutter.game.Account)1 LoginResultJson (emu.grasscutter.server.http.objects.LoginResultJson)1