extractRequestParams(); $token = $params['token']; $maxage = $params['maxtokenage']; $salts = ApiQueryTokens::getTokenTypeSalts(); $res = []; $tokenObj = ApiQueryTokens::getToken( $this->getUser(), $this->getRequest()->getSession(), $salts[$params['type']] ); if ( substr( $token, -strlen( urldecode( Token::SUFFIX ) ) ) === urldecode( Token::SUFFIX ) ) { $this->addWarning( 'apiwarn-checktoken-percentencoding' ); } if ( $tokenObj->match( $token, $maxage ) ) { $res['result'] = 'valid'; } elseif ( $maxage !== null && $tokenObj->match( $token ) ) { $res['result'] = 'expired'; } else { $res['result'] = 'invalid'; } $ts = Token::getTimestamp( $token ); if ( $ts !== null ) { $mwts = new MWTimestamp(); $mwts->timestamp->setTimestamp( $ts ); $res['generated'] = $mwts->getTimestamp( TS_ISO_8601 ); } $this->getResult()->addValue( null, $this->getModuleName(), $res ); } public function getAllowedParams() { return [ 'type' => [ ApiBase::PARAM_TYPE => array_keys( ApiQueryTokens::getTokenTypeSalts() ), ApiBase::PARAM_REQUIRED => true, ], 'token' => [ ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_REQUIRED => true, ApiBase::PARAM_SENSITIVE => true, ], 'maxtokenage' => [ ApiBase::PARAM_TYPE => 'integer', ], ]; } protected function getExamplesMessages() { return [ 'action=checktoken&type=csrf&token=123ABC' => 'apihelp-checktoken-example-simple', ]; } }