Skip to content
Snippets Groups Projects
Select Git revision
  • 04df327939cbf82b5846f202a6c4546cc0aa53ab
  • master default protected
  • rednatco-v2
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • servers
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

structure-element-selection.ts

Blame
  • action.php 2.08 KiB
    <?php
    
    use dokuwiki\plugin\oauth\Adapter;
    use dokuwiki\plugin\oauthgeneric\DotAccess;
    use dokuwiki\plugin\oauthgeneric\Generic;
    
    /**
     * Service Implementation for oAuth Doorkeeper authentication
     */
    class action_plugin_oauthgeneric extends Adapter
    {
    
        /** @inheritdoc */
        public function registerServiceClass()
        {
            return Generic::class;
        }
    
        /** * @inheritDoc */
        public function getUser()
        {
            $oauth = $this->getOAuthService();
            $data = array();
    
            $url = $this->getConf('userurl');
            $raw = $oauth->request($url);
    
            if (!$raw) throw new OAuthException('Failed to fetch data from userurl');
            $result = json_decode($raw, true);
            if (!$result) throw new OAuthException('Failed to parse data from userurl');
    
            $user = DotAccess::get($result, $this->getConf('json-user'), '');
            $name = DotAccess::get($result, $this->getConf('json-name'), '');
            $mail = DotAccess::get($result, $this->getConf('json-mail'), '');
            $grps = DotAccess::get($result, $this->getConf('json-grps'), []);
    
            // type fixes
            if (is_array($user)) $user = array_shift($user);
            if (is_array($name)) $user = array_shift($name);
            if (is_array($mail)) $user = array_shift($mail);
            if (!is_array($grps)) {
                $grps = explode(',', $grps);
                $grps = array_map('trim', $grps);
            }
    
            // fallbacks for user name
            if (empty($user)) {
                if (!empty($name)) {
                    $user = $name;
                } elseif (!empty($mail)) {
                    list($user) = explode('@', $mail);
                }
            }
    
            // fallback for full name
            if (empty($name)) {
                $name = $user;
            }
    
            return compact('user', 'name', 'mail', 'grps');
        }
    
        /** @inheritdoc */
        public function getScopes()
        {
            return $this->getConf('scopes');
        }
    
        /** @inheritDoc */
        public function getLabel()
        {
            return $this->getConf('label');
        }
    
        /** @inheritDoc */
        public function getColor()
        {
            return $this->getConf('color');
        }
    }