Skip to content

Error when using Scopes #148

@livingos

Description

@livingos

If you try to use scopes middllewere, CheckScopes and CheckAnyScope you get the following error, provided you have an access token generated with a scope:

ErrorException: in_array() expects parameter 2 to be array, string given in /home/vagrant/Code/laravel53/vendor/laravel/passport/src/Token.php:74

I believe the problem is being caused when the scopes are stored in the oauth_access_token table.

FormatsScopesForStorage is used to format the scopes before writing to both the oauth_access_token and oauth_auth_code tables. BUT the Token.php model is using the eloquent cast feature (though Auth_Code isn't!?).

The result is that the scopes stored in oauth_access_token have been json encoded twice, so that when CheckScope uses the can(scope) method, the above error is fired. $this->scopes returns a string that can be decoded again to get the array.

So a very quick dirty fix is to decode the scopes (again) in the can method. Which makes scopes actually work, which they don't at all at present as far as I can see.

Or is there some strange quirk on my system? Surprised no one has noticed this, since scopes do not work at all!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions