title: Single Sign On from WordPress to media wiki
body: <p>I am trying to create Single sign-on from Wordpress to MediaWiki. I have WPOauthServer running on my WordPress (Wordpress plugin). And on my wiki I have  <a href="https://www.mediawiki.org/wiki/Extension:OAuth2_Client" rel="nofollow noreferrer">Extension:OAuth2 Client</a> installed. I want that my users only log in to WordPress and from there they can go to the wiki without logging to wiki again. The WPOauthServer is working fine, I am using the Grant type <code>Authorization Code</code>. I have tested by using <code>curl</code> and I am able to get the authorization code and using the authorization code I can acquire authentication token.</p>
  
  <p>I have a button on my wordpress page with client id:</p>
  
  <pre><code>&lt;a href="https://xxxxxx.de/oauth/authorize?response_type=code&amp;client_id=XXXXXXXXX&amp;state=123"&gt;Connect Your Account&lt;/a&gt;
  </code></pre>
  
  <p>When I open the authorization link, I am redirected to the following <code>redirect-URI</code> that was set in client settings at server side:</p>
  
  <pre><code>https://wiki.XXXXXXXXXXXXX.de/wiki/Special:OAuth2Client/callback?code=farkmm4ttuwxnne8a9firwtdikmite788hwpyhzg&amp;state=123 
  </code></pre>
  
  <p>and here I get an internal error:</p>
  
  <p><code>Fatal exception of type "GuzzleHttp\Exception\RequestException</code> </p>
  
  <p>upon digging i found out that this exception is caused in the extension file <code>AbstractProvider.php</code> in the <code>sendRequest</code> function:</p>
  
  <pre><code>/**
   * Sends a request instance and returns a response instance.
   *
   * @param  RequestInterface $request
   * @return ResponseInterface
   */
  protected function sendRequest(RequestInterface $request)
  {
      try {
          var_dump($request);
          $response = $this-&gt;getHttpClient()-&gt;send($request);
          var_dump($response);
      } catch (BadResponseException $e) {
          $response = $e-&gt;getResponse();
      }
      return $response;
  }
  </code></pre>
  
  <p>the exception is caused in <code>$response = $this-&gt;getHttpClient()-&gt;send($request);</code></p>
  
  <p>I think maybe there is something wrong with my request, doing a <code>var_dump</code> on request reveals the following:</p>
  
  <pre><code>/var/www/mediawiki/w/extensions/MW-OAuth2Client/vendors/oauth2-client/src/Provider/AbstractProvider.php:629:
  object(GuzzleHttp\Psr7\Request)[278]
    private 'method' =&gt; string 'POST' (length=4)
    private 'requestTarget' =&gt; null
    private 'uri' =&gt; 
      object(GuzzleHttp\Psr7\Uri)[279]
        private 'scheme' =&gt; string 'https' (length=5)
        private 'userInfo' =&gt; string '' (length=0)
        private 'host' =&gt; string 'xxxxxxx.de' (length=13)
        private 'port' =&gt; null
        private 'path' =&gt; string '/oauth/token/' (length=13)
        private 'query' =&gt; string '' (length=0)
        private 'fragment' =&gt; string '' (length=0)
    private 'headers' =&gt; 
      array (size=2)
        'Host' =&gt; 
          array (size=1)
            0 =&gt; string 'xxxxxx.de' (length=13)
        'content-type' =&gt; 
          array (size=1)
            0 =&gt; string 'application/x-www-form-urlencoded' (length=33)
    private 'headerNames' =&gt; 
      array (size=2)
        'content-type' =&gt; string 'content-type' (length=12)
        'host' =&gt; string 'Host' (length=4)
    private 'protocol' =&gt; string '1.1' (length=3)
    private 'stream' =&gt; 
      object(GuzzleHttp\Psr7\Stream)[287]
        private 'stream' =&gt; resource(18, stream)
        private 'size' =&gt; null
        private 'seekable' =&gt; boolean true
        private 'readable' =&gt; boolean true
        private 'writable' =&gt; boolean true
        private 'uri' =&gt; string 'php://temp' (length=10)
        private 'customMetadata' =&gt; 
          array (size=0)
            empty
  </code></pre>
  
  <p>The stack trace from apache logs:</p>
  
  <pre><code> Notice:  Undefined index: scopes in /var/www/mediawiki/w/extensions/MW-OAuth2Client/SpecialOAuth2Client.php on line 54, referer: https://XXXXXXerv.de/sso-test/
   Stack trace:, referer: https://XXXXXXerv.de/sso-test/
     1. {main}() /var/www/mediawiki/w/index.php:0, referer: https://XXXXXXerv.de/sso-test/
     2. MediaWiki-&gt;run() /var/www/mediawiki/w/index.php:42, referer: https://XXXXXXerv.de/sso-test/
     3. MediaWiki-&gt;main() /var/www/mediawiki/w/includes/MediaWiki.php:524, referer: https://XXXXXXerv.de/sso-test/
     4. MediaWiki-&gt;performRequest() /var/www/mediawiki/w/includes/MediaWiki.php:861, referer: https://XXXXXXerv.de/sso-test/
     5. SpecialPageFactory::getPage() /var/www/mediawiki/w/includes/MediaWiki.php:255, referer: https://XXXXXXerv.de/sso-test/
     6. SpecialOAuth2Client-&gt;__construct() /var/www/mediawiki/w/includes/specialpage/SpecialPageFactory.php:382, referer: https://XXXXXXerv.de/sso-test/
   Notice:  Undefined index: scopes in /var/www/mediawiki/w/extensions/MW-OAuth2Client/SpecialOAuth2Client.php on line 54, referer: https://XXXXXXerv.de/sso-test/
   Stack trace:, referer: https://XXXXXXerv.de/sso-test/
     1. {main}() /var/www/mediawiki/w/index.php:0, referer: https://XXXXXXerv.de/sso-test/
     2. MediaWiki-&gt;run() /var/www/mediawiki/w/index.php:42, referer: https://XXXXXXerv.de/sso-test/
     3. MediaWiki-&gt;main() /var/www/mediawiki/w/includes/MediaWiki.php:524, referer: https://XXXXXXerv.de/sso-test/
     4. MediaWiki-&gt;performRequest() /var/www/mediawiki/w/includes/MediaWiki.php:861, referer: https://XXXXXXerv.de/sso-test/
     5. SpecialPageFactory::executePath() /var/www/mediawiki/w/includes/MediaWiki.php:288, referer: https://XXXXXXerv.de/sso-test/
     6. SpecialPageFactory::getPage() /var/www/mediawiki/w/includes/specialpage/SpecialPageFactory.php:513, referer: https://XXXXXXerv.de/sso-test/
     7. SpecialOAuth2Client-&gt;__construct() /var/www/mediawiki/w/includes/specialpage/SpecialPageFactory.php:382, referer: https://XXXXXXerv.de/sso-test/
  </code></pre>
  
  <p><strong>EDIT:</strong>
  From the stack trace, I realized that <code>scope</code> is not defined in the media wiki client settings in <code>localsettings.php</code>, so after setting the scope I don't get any errors in the apache logs but media wiki still shows internal error <code>Fatal exception of type "GuzzleHttp\Exception\RequestException</code></p>
  
  <p>Upon more digging, I found out that I was getting a <code>curl: (60) SSL certificate: unable to get local issuer certificate</code> error which I solved by adding the CA Root to my trusted CA for more information see <a href="https://stackoverflow.com/questions/7587851/openssl-unable-to-verify-the-first-certificate-for-experian-url/36732942#36732942">this post </a></p>
  
  <p>After solving this issue I just needed to correct the following:</p>
  
  <pre><code>$wgOAuth2Client['configuration']['username'] = 'user_login'; // JSON path to username
  $wgOAuth2Client['configuration']['email'] = 'user_email'; // JSON path to email
  </code></pre>
  
  <p>see the answer for implenting SSO from WordPress</p>