UseMuffin / OAuth2

CakePHP 3 authentication using the league/oauth2-client.
MIT License
26 stars 12 forks source link

No way to update user in local database after login #12

Open LiaraAlis opened 7 years ago

LiaraAlis commented 7 years ago

If I want to update the user data for a existing user in my local database, I have no way to do this easily. The afterIdentify event is fired without the informations from the OAuth server. Additionaly, it is fired even if the user is previously created in database. If I get the resource owner details, I can't map the values as the class OAuthAuthenticate to this.

Is there a problem to modify the _touch- method as follows and implement a new event?

    protected function _touch(array $data)
    {
        if ($result = $this->_findUser($data[$this->config('fields.username')])) {
            $result = array_merge($data, $result);
            $args = [$this->_provider, $result];
            $event = $this->dispatchEvent('Muffin/OAuth2.updateUser', $args);
            return empty($event->result) ? $result : $event->result;
        }

        $event = 'Muffin/OAuth2.newUser';
        $args = [$this->_provider, $data];
        $event = $this->dispatchEvent($event, $args);
        if (empty($event->result)) {
            throw new MissingEventListenerException([$event]);
        }

        return $event->result;
    }
zunderbolt commented 7 years ago

+1

kojot1234 commented 7 years ago

+1