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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
bitly.php
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 * Bitly OAuth service
018 */
019 class bitly 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_service_credentials()
043 {
044 return [
045 'key' => $this->config['auth_oauth_bitly_key'],
046 'secret' => $this->config['auth_oauth_bitly_secret'],
047 ];
048 }
049
050 /**
051 * {@inheritdoc}
052 */
053 public function perform_auth_login()
054 {
055 if (!($this->service_provider instanceof \OAuth\OAuth2\Service\Bitly))
056 {
057 throw new exception('AUTH_PROVIDER_OAUTH_ERROR_INVALID_SERVICE_TYPE');
058 }
059
060 try
061 {
062 // This was a callback request, get the token
063 $this->service_provider->requestAccessToken($this->request->variable('code', ''));
064 }
065 catch (\OAuth\Common\Http\Exception\TokenResponseException $e)
066 {
067 throw new exception('AUTH_PROVIDER_OAUTH_ERROR_REQUEST');
068 }
069
070 try
071 {
072 // Send a request with it
073 $result = (array) json_decode($this->service_provider->request('user/info'), true);
074 }
075 catch (\OAuth\Common\Exception\Exception $e)
076 {
077 throw new exception('AUTH_PROVIDER_OAUTH_ERROR_REQUEST');
078 }
079
080 // Prevent SQL error
081 if (!isset($result['data']['login']))
082 {
083 throw new exception('AUTH_PROVIDER_OAUTH_RETURN_ERROR');
084 }
085
086 // Return the unique identifier returned from bitly
087 return $result['data']['login'];
088 }
089
090 /**
091 * {@inheritdoc}
092 */
093 public function perform_token_auth()
094 {
095 if (!($this->service_provider instanceof \OAuth\OAuth2\Service\Bitly))
096 {
097 throw new exception('AUTH_PROVIDER_OAUTH_ERROR_INVALID_SERVICE_TYPE');
098 }
099
100 try
101 {
102 // Send a request with it
103 $result = (array) json_decode($this->service_provider->request('user/info'), true);
104 }
105 catch (\OAuth\Common\Exception\Exception $e)
106 {
107 throw new exception('AUTH_PROVIDER_OAUTH_ERROR_REQUEST');
108 }
109
110 // Prevent SQL error
111 if (!isset($result['data']['login']))
112 {
113 throw new exception('AUTH_PROVIDER_OAUTH_RETURN_ERROR');
114 }
115
116 // Return the unique identifier
117 return $result['data']['login'];
118 }
119 }
120