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);
}
Aggregations