1<?php 2 3use OAuth\OAuth2\Service\GitHub; 4 5/** 6 * Service Implementation for oAuth Github authentication 7 */ 8class action_plugin_oauthgithub extends \dokuwiki\plugin\oauth\Adapter 9{ 10 11 /** * @inheritDoc */ 12 public function getUser() 13 { 14 $oauth = $this->getOAuthService(); 15 $data = array(); 16 17 // basic user data 18 $result = json_decode($oauth->request('user'), true); 19 $data['user'] = $result['login']; 20 $data['name'] = $result['name']; 21 22 // primary email address 23 $result = json_decode($oauth->request('user/emails'), true); 24 foreach ($result as $row) { 25 if (!empty($row['primary']) && !empty($row['verified'])) { 26 $data['mail'] = $row['email']; 27 break; 28 } 29 } 30 31 return $data; 32 } 33 34 /** @inheritDoc */ 35 public function getScopes() 36 { 37 return [GitHub::SCOPE_USER_EMAIL]; 38 } 39 40 /** @inheritDoc */ 41 public function getLabel() 42 { 43 return 'GitHub'; 44 } 45 46 /** @inheritDoc */ 47 public function getColor() 48 { 49 return '#404041'; 50 } 51 52} 53