Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Setup
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 onTestCanonicalRedirect
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isOAuthRequest
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace MediaWiki\Extension\OAuth;
4
5use MediaWiki\Extension\OAuth\Backend\Utils;
6use MediaWiki\Hook\TestCanonicalRedirectHook;
7use MediaWiki\Output\OutputPage;
8use MediaWiki\Request\WebRequest;
9use MediaWiki\Title\Title;
10
11/**
12 * Class containing hooked functions for an OAuth environment
13 */
14class Setup implements TestCanonicalRedirectHook {
15    /**
16     * Prevent redirects to canonical titles, since that's not what the OAuth
17     * request signed.
18     * @param WebRequest $request
19     * @param Title $title
20     * @param OutputPage $output
21     * @return bool
22     */
23    public function onTestCanonicalRedirect( $request, $title, $output ) {
24        return !self::isOAuthRequest( $request );
25    }
26
27    protected static function isOAuthRequest( $request ) {
28        if ( Utils::hasOAuthHeaders( $request ) ) {
29            return true;
30        }
31        return ResourceServer::isOAuth2Request( $request );
32    }
33}