[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 namespace phpbb\auth\provider\oauth\service; 15 16 /** 17 * Google OAuth service 18 */ 19 class google extends base 20 { 21 /** 22 * phpBB config 23 * 24 * @var \phpbb\config\config 25 */ 26 protected $config; 27 28 /** 29 * phpBB request 30 * 31 * @var \phpbb\request\request_interface 32 */ 33 protected $request; 34 35 /** 36 * Constructor 37 * 38 * @param \phpbb\config\config $config 39 * @param \phpbb\request\request_interface $request 40 */ 41 public function __construct(\phpbb\config\config $config, \phpbb\request\request_interface $request) 42 { 43 $this->config = $config; 44 $this->request = $request; 45 } 46 47 /** 48 * {@inheritdoc} 49 */ 50 public function get_auth_scope() 51 { 52 return array( 53 'userinfo_email', 54 'userinfo_profile', 55 ); 56 } 57 58 /** 59 * {@inheritdoc} 60 */ 61 public function get_service_credentials() 62 { 63 return array( 64 'key' => $this->config['auth_oauth_google_key'], 65 'secret' => $this->config['auth_oauth_google_secret'], 66 ); 67 } 68 69 /** 70 * {@inheritdoc} 71 */ 72 public function perform_auth_login() 73 { 74 if (!($this->service_provider instanceof \OAuth\OAuth2\Service\Google)) 75 { 76 throw new exception('AUTH_PROVIDER_OAUTH_ERROR_INVALID_SERVICE_TYPE'); 77 } 78 79 // This was a callback request, get the token 80 $this->service_provider->requestAccessToken($this->request->variable('code', '')); 81 82 // Send a request with it 83 $result = json_decode($this->service_provider->request('https://www.googleapis.com/oauth2/v1/userinfo'), true); 84 85 // Return the unique identifier 86 return $result['id']; 87 } 88 89 /** 90 * {@inheritdoc} 91 */ 92 public function perform_token_auth() 93 { 94 if (!($this->service_provider instanceof \OAuth\OAuth2\Service\Google)) 95 { 96 throw new exception('AUTH_PROVIDER_OAUTH_ERROR_INVALID_SERVICE_TYPE'); 97 } 98 99 // Send a request with it 100 $result = json_decode($this->service_provider->request('https://www.googleapis.com/oauth2/v1/userinfo'), true); 101 102 // Return the unique identifier 103 return $result['id']; 104 } 105 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |