bshaffer / oauth2-server-php

A library for implementing an OAuth2 Server in php
http://bshaffer.github.io/oauth2-server-php-docs
MIT License
3.26k stars 950 forks source link

MongoDB storage needs convert token to array from BSONDocument #835

Closed fernandoigual closed 7 years ago

fernandoigual commented 7 years ago

Hi,

Whe I use MongoDB storage I get an error in library chadicus/slim-oauth2-middleware because expects an array instead of a BSONDocument :

Argument 1 passed to Chadicus\Slim\OAuth2\Middleware\Authorization::setToken() must be of the type array, object given, called in E:\nando\Proyectos\LemonKey\api\vendor\chadicus\slim-oauth2-middleware\src\Authorization.php on line 79

This could be fixed in ResourceController.php:69 casting token to array:

    // allow retrieval of the token
    $this->token = (array)$token;
chadicus commented 7 years ago

Construct your mongo client with a typemap which converts all types to arrays. http://php.net/manual/en/mongodb.persistence.deserialization.php#mongodb.persistence.typemaps

chadicus commented 7 years ago

@fernandoigual I have updated the MongoDB example in the slim-oauth2 package. Hopefully, this will help resolve your issue.

fernandoigual commented 7 years ago

Perfect! Thank you.