0
votes

Comment vérifier qu'une ficelle est JWT Jetken?

en java Comment vérifier que la chaîne que j'ai donnée est un jeton JWT sans utiliser de signature?

J'utilise xxx

Ceci fonctionne bien mais je veux vérifier Ceci sans secret_key .

Je veux juste vérifier s'il s'agit d'un jeton JWT ou non.


0 commentaires

3 Réponses :


0
votes

Vous pouvez décoder JWT de base64 et vérifier nécessairement le champ. Ou simplement vérifier le jeton, pourquoi vous voulez vérifier cela, ce n'est pas plus rapide que Simpy Vérifiez-le.


0 commentaires

0
votes

Essayez celui-ci. XXX PRE>

Ensuite, vous devez obtenir de l'organisme JWT cette partie qui est importante pour vous, par exemple. P>

JSONObject body = JWTUtils.getPayload(token);
        String username = body.getString("username");


0 commentaires

1
votes

Voici un exemple pour vérifier la structure du JWT. Il vous suffit d'ajouter les validations des données que le JWT doit transporter

boolean isJWT(String jwt) {
        String[] jwtSplitted = jwt.split("\\.");
        if (jwtSplitted.length != 3) // The JWT is composed of three parts
            return false;
        try {
            String jsonFirstPart = new String(Base64.getDecoder().decode(jwtSplitted[0]));
            JSONObject firstPart = new JSONObject(jsonFirstPart); // The first part of the JWT is a JSON
            if (!firstPart.has("alg")) // The first part has the attribute "alg"
                return false;
            String jsonSecondPart = new String(Base64.getDecoder().decode(jwtSplitted[1]));
            JSONObject secondPart = new JSONObject(jsonSecondPart); // The first part of the JWT is a JSON
            //Put the validations you think are necessary for the data the JWT should take to validate
        }catch (JSONException err){
            return false;
        }
        return true;
    }


1 commentaires

Cela a fonctionné pour moi