services/src/main/java/org/keycloak/protocol/oidc/endpoints/ValidateTokenEndpoint.java
/**
     * Validate encoded access token.
     *
     * @param tokenString
     * @return Unmarshalled token
     */
Validate encoded access token.
@param tokenString
@return Unmarshalled token
Validate encoded access token . @param tokenString @return Unmarshalled token
@GET
    @NoCache
    @Produces(MediaType.APPLICATION_JSON)
    public Response validateAccessToken(@QueryParam("access_token") String tokenString) {
        checkSsl();
        event.event(EventType.VALIDATE_ACCESS_TOKEN);
        AccessToken token = null;
        try {
            token = RSATokenVerifier.verifyToken(tokenString, realm.getPublicKey(), Urls.realmIssuer(uriInfo.getBaseUri(), realm.getName()));
        } catch (Exception e) {
            Map<String, String> err = new HashMap<String, String>();
            err.put(OAuth2Constants.ERROR, OAuthErrorException.INVALID_GRANT);
            err.put(OAuth2Constants.ERROR_DESCRIPTION, "Token invalid");
            logger.error("Invalid token. Token verification failed.");
            event.error(Errors.INVALID_TOKEN);
            return Response.status(Response.Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON_TYPE).entity(err)
                    .build();
        }
        event.user(token.getSubject()).session(token.getSessionState()).detail(Details.VALIDATE_ACCESS_TOKEN, token.getId());
        try {
            tokenManager.validateToken(session, uriInfo, clientConnection, realm, token, headers);
        } catch (OAuthErrorException e) {
            Map<String, String> error = new HashMap<String, String>();
            error.put(OAuth2Constants.ERROR, e.getError());
            if (e.getDescription() != null) error.put(OAuth2Constants.ERROR_DESCRIPTION, e.getDescription());
            event.error(Errors.INVALID_TOKEN);
            return Response.status(Response.Status.BAD_REQUEST).entity(error).type(MediaType.APPLICATION_JSON_TYPE).build();
        }
        event.success();
        return Response.ok(token, MediaType.APPLICATION_JSON_TYPE).build();
    }
@ GET @ NoCache @ Produces ( MediaType . APPLICATION_JSON ) public Response validateAccessToken ( @ QueryParam ( "access_token" ) String tokenString ) { checkSsl ( ) ; event . event ( EventType . VALIDATE_ACCESS_TOKEN ) ; AccessToken token = null ; try { token = RSATokenVerifier . verifyToken ( tokenString , realm . getPublicKey ( ) , Urls . realmIssuer ( uriInfo . getBaseUri ( ) , realm . getName ( ) ) ) ; } catch ( Exception e ) { Map < String , String > err = new HashMap < String , String > ( ) ; err . put ( OAuth2Constants . ERROR , OAuthErrorException . INVALID_GRANT ) ; err . put ( OAuth2Constants . ERROR_DESCRIPTION , "Token invalid" ) ; logger . error ( "Invalid token. Token verification failed." ) ; event . error ( Errors . INVALID_TOKEN ) ; return Response . status ( Response . Status . BAD_REQUEST ) . type ( MediaType . APPLICATION_JSON_TYPE ) . entity ( err ) . build ( ) ; } event . user ( token . getSubject ( ) ) . session ( token . getSessionState ( ) ) . detail ( Details . VALIDATE_ACCESS_TOKEN , token . getId ( ) ) ; try { tokenManager . validateToken ( session , uriInfo , clientConnection , realm , token , headers ) ; } catch ( OAuthErrorException e ) { Map < String , String > error = new HashMap < String , String > ( ) ; error . put ( OAuth2Constants . ERROR , e . getError ( ) ) ; if ( e . getDescription ( ) != null ) error . put ( OAuth2Constants . ERROR_DESCRIPTION , e . getDescription ( ) ) ; event . error ( Errors . INVALID_TOKEN ) ; return Response . status ( Response . Status . BAD_REQUEST ) . entity ( error ) . type ( MediaType . APPLICATION_JSON_TYPE ) . build ( ) ; } event . success ( ) ; return Response . ok ( token , MediaType . APPLICATION_JSON_TYPE ) . build ( ) ; }
Validate encoded access token.
Validate encoded access token .