1<?php 2 3use dokuwiki\plugin\oauth\Adapter; 4use dokuwiki\plugin\oauthdiscord\Discord; 5 6/** 7 * Service Implementation for oAuth Doorkeeper authentication 8 */ 9class action_plugin_oauthdiscord extends Adapter 10{ 11 12 /** 13 * @inheritdoc 14 */ 15 public function registerServiceClass() 16 { 17 return Discord::class; 18 } 19 20 /** 21 * @inheritDoc 22 */ 23 public function getUser() 24 { 25 $oauth = $this->getOAuthService(); 26 $data = array(); 27 28 // basic user data 29 $result = json_decode($oauth->request('https://discord.com/api/users/@me'), true); 30 $data['user'] = $result['username']; 31 $data['name'] = $result['global_name']; 32 33 if ($result['verified']) { 34 $data['mail'] = $result['email']; 35 } 36 37 return $data; 38 } 39 40 /** 41 * @inheritdoc 42 */ 43 public function getScopes() 44 { 45 return [Discord::SCOPE_IDENTIFY, Discord::SCOPE_EMAIL]; 46 } 47 48 /** 49 * @inheritDoc 50 */ 51 public function getLabel() 52 { 53 return 'Discord'; 54 } 55 56 /** 57 * @inheritDoc 58 */ 59 public function getColor() 60 { 61 return '#7289da'; 62 } 63} 64