Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

google.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 2.54 KiB


001  <?php
002  /**
003   *
004   * This file is part of the phpBB Forum Software package.
005   *
006   * @copyright (c) phpBB Limited <https://www.phpbb.com>
007   * @license GNU General Public License, version 2 (GPL-2.0)
008   *
009   * For full copyright and license information, please see
010   * the docs/CREDITS.txt file.
011   *
012   */
013   
014  namespace phpbb\auth\provider\oauth\service;
015   
016  /**
017   * Google OAuth service
018   */
019  class google extends base
020  {
021      /** @var \phpbb\config\config */
022      protected $config;
023   
024      /** @var \phpbb\request\request_interface */
025      protected $request;
026   
027      /**
028       * Constructor.
029       *
030       * @param \phpbb\config\config                $config        Config object
031       * @param \phpbb\request\request_interface    $request    Request object
032       */
033      public function __construct(\phpbb\config\config $config, \phpbb\request\request_interface $request)
034      {
035          $this->config    = $config;
036          $this->request    = $request;
037      }
038   
039      /**
040       * {@inheritdoc}
041       */
042      public function get_auth_scope()
043      {
044          return [
045              'userinfo_email',
046              'userinfo_profile',
047          ];
048      }
049   
050      /**
051       * {@inheritdoc}
052       */
053      public function get_service_credentials()
054      {
055          return [
056              'key'        => $this->config['auth_oauth_google_key'],
057              'secret'    => $this->config['auth_oauth_google_secret'],
058          ];
059      }
060   
061      /**
062       * {@inheritdoc}
063       */
064      public function perform_auth_login()
065      {
066          if (!($this->service_provider instanceof \OAuth\OAuth2\Service\Google))
067          {
068              throw new exception('AUTH_PROVIDER_OAUTH_ERROR_INVALID_SERVICE_TYPE');
069          }
070   
071          try
072          {
073              // This was a callback request, get the token
074              $this->service_provider->requestAccessToken($this->request->variable('code', ''));
075          }
076          catch (\OAuth\Common\Http\Exception\TokenResponseException $e)
077          {
078              throw new exception('AUTH_PROVIDER_OAUTH_ERROR_REQUEST');
079          }
080   
081          try
082          {
083              // Send a request with it
084              $result = (array) json_decode($this->service_provider->request('https://www.googleapis.com/oauth2/v1/userinfo'), true);
085          }
086          catch (\OAuth\Common\Exception\Exception $e)
087          {
088              throw new exception('AUTH_PROVIDER_OAUTH_ERROR_REQUEST');
089          }
090   
091          // Return the unique identifier
092          return $result['id'];
093      }
094   
095      /**
096       * {@inheritdoc}
097       */
098      public function perform_token_auth()
099      {
100          if (!($this->service_provider instanceof \OAuth\OAuth2\Service\Google))
101          {
102              throw new exception('AUTH_PROVIDER_OAUTH_ERROR_INVALID_SERVICE_TYPE');
103          }
104   
105          try
106          {
107              // Send a request with it
108              $result = (array) json_decode($this->service_provider->request('https://www.googleapis.com/oauth2/v1/userinfo'), true);
109          }
110          catch (\OAuth\Common\Exception\Exception $e)
111          {
112              throw new exception('AUTH_PROVIDER_OAUTH_ERROR_REQUEST');
113          }
114   
115          // Return the unique identifier
116          return $result['id'];
117      }
118  }
119