41 private $isApiRequest;
52 if ( !isset( $params[
'sessionCookieName'] ) ) {
53 $params[
'sessionCookieName'] =
'_BPsession';
55 parent::__construct( $params );
57 if ( !isset( $params[
'priority'] ) ) {
58 throw new \InvalidArgumentException( __METHOD__ .
': priority must be specified' );
63 throw new \InvalidArgumentException( __METHOD__ .
': Invalid priority' );
66 $this->priority = $params[
'priority'];
68 $this->grantsInfo = $grantsInfo;
70 $this->isApiRequest = $params[
'isApiRequest']
71 ?? ( defined(
'MW_API' ) || defined(
'MW_REST_API' ) );
76 if ( !$this->isApiRequest ) {
116 'persisted' => $id !==
null,
121 'rights' => $this->grantsInfo->getGrantRights( $bp->
getGrants() ),
124 $session = $this->
getManager()->getSessionFromInfo( $info, $request );
134 $missingKeys = array_diff(
135 [
'centralId',
'appId',
'token' ],
136 array_keys( $metadata )
138 if ( $missingKeys ) {
139 $this->logger->info(
'Session "{session}": Missing metadata: {missing}', [
141 'missing' => implode(
', ', $missingKeys ),
146 $bp = BotPassword::newFromCentralId( $metadata[
'centralId'], $metadata[
'appId'] );
149 'Session "{session}": No BotPassword for {centralId} {appId}',
152 'centralId' => $metadata[
'centralId'],
153 'appId' => $metadata[
'appId'],
158 if ( !hash_equals( $metadata[
'token'], $bp->getToken() ) ) {
159 $this->logger->info(
'Session "{session}": BotPassword token check failed', [
161 'centralId' => $metadata[
'centralId'],
162 'appId' => $metadata[
'appId'],
167 $status = $bp->getRestrictions()->check( $request );
168 if ( !$status->isOK() ) {
170 'Session "{session}": Restrictions check failed',
173 'restrictions' => $status->getValue(),
174 'centralId' => $metadata[
'centralId'],
175 'appId' => $metadata[
'appId'],
181 $metadata[
'rights'] = $this->grantsInfo->getGrantRights( $bp->getGrants() );
191 BotPassword::removeAllPasswordsForUser( $username );
196 throw new \InvalidArgumentException(
'Backend\'s provider isn\'t $this' );
199 if ( $data && isset( $data[
'rights'] ) && is_array( $data[
'rights'] ) ) {
200 return $data[
'rights'];
204 $this->logger->debug( __METHOD__ .
': No provider metadata, returning no rights allowed' );
A class containing constants representing the names of configuration variables.
const EnableBotPasswords
Name constant for the EnableBotPasswords setting, for use with Config::get()