designmynight / laravel-mongodb-passport

A package to get Laravel Passport working with MongoDB
MIT License
67 stars 75 forks source link

BadMethodCallException "Client::confidential()" #35

Open Khalilbz opened 4 years ago

Khalilbz commented 4 years ago

I'm getting this error, and I didn't understand why Call to undefined method DesignMyNight\\Mongodb\\Passport\\Client::confidential() Knowing that I'm using MongoDB as a database

I sent a POST request with this header and body: Header: Content-Type:application/json Accept:application/json Body: { "email": "khalil@gmail.com", "password": "123456" }

My Controller function :

public function login(Request $request)
    {
        $request->validate([
            'email' => 'required|email',
            'password' => 'required|min:6'
        ]);
        if(Auth::attempt(["email" => $request->email, "password" => $request->password])){
            $user = Auth::user();
            $token = $user->createToken($user->email."-".now());
            $token = $token->accessToken;
            return response()->json([
                "token" => $token
            ]);
        }
    }

My composer.json file:

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.2",
        "designmynight/laravel-mongodb-passport": "^1.2",
        "fideloper/proxy": "^4.0",
        "jenssegers/mongodb": "^3.6",
        "laravel/framework": "^6.2",
        "laravel/tinker": "^2.0"
    },
    "require-dev": {
        "facade/ignition": "^1.4",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^3.0",
        "phpunit/phpunit": "^8.0"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}

My User Model:

<?php

namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use DesignMyNight\Mongodb\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;

class User extends Authenticatable
{
    use Notifiable, HasApiTokens;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
}

The Return:

{
    "message": "Call to undefined method DesignMyNight\\Mongodb\\Passport\\Client::confidential()",
    "exception": "BadMethodCallException",
    "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php",
    "line": 50,
    "trace": [
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php",
            "line": 36,
            "function": "throwBadMethodCallException",
            "class": "Illuminate\\Database\\Eloquent\\Model",
            "type": "::"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php",
            "line": 1620,
            "function": "forwardCallTo",
            "class": "Illuminate\\Database\\Eloquent\\Model",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/Eloquent/Model.php",
            "line": 480,
            "function": "__call",
            "class": "Illuminate\\Database\\Eloquent\\Model",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/passport/src/Bridge/ClientRepository.php",
            "line": 78,
            "function": "__call",
            "class": "Jenssegers\\Mongodb\\Eloquent\\Model",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/passport/src/Bridge/ClientRepository.php",
            "line": 54,
            "function": "handlesGrant",
            "class": "Laravel\\Passport\\Bridge\\ClientRepository",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/league/oauth2-server/src/Grant/AbstractGrant.php",
            "line": 182,
            "function": "validateClient",
            "class": "Laravel\\Passport\\Bridge\\ClientRepository",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/passport/src/Bridge/PersonalAccessGrant.php",
            "line": 21,
            "function": "validateClient",
            "class": "League\\OAuth2\\Server\\Grant\\AbstractGrant",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/league/oauth2-server/src/AuthorizationServer.php",
            "line": 198,
            "function": "respondToAccessTokenRequest",
            "class": "Laravel\\Passport\\Bridge\\PersonalAccessGrant",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/passport/src/PersonalAccessTokenFactory.php",
            "line": 114,
            "function": "respondToAccessTokenRequest",
            "class": "League\\OAuth2\\Server\\AuthorizationServer",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/passport/src/PersonalAccessTokenFactory.php",
            "line": 71,
            "function": "dispatchRequestToAuthorizationServer",
            "class": "Laravel\\Passport\\PersonalAccessTokenFactory",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/passport/src/HasApiTokens.php",
            "line": 67,
            "function": "make",
            "class": "Laravel\\Passport\\PersonalAccessTokenFactory",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/app/Http/Controllers/AuthController.php",
            "line": 48,
            "function": "createToken",
            "class": "App\\User",
            "type": "->"
        },
        {
            "function": "login",
            "class": "App\\Http\\Controllers\\AuthController",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Routing/Controller.php",
            "line": 54,
            "function": "call_user_func_array"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php",
            "line": 45,
            "function": "callAction",
            "class": "Illuminate\\Routing\\Controller",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
            "line": 219,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\ControllerDispatcher",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
            "line": 176,
            "function": "runController",
            "class": "Illuminate\\Routing\\Route",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 681,
            "function": "run",
            "class": "Illuminate\\Routing\\Route",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 130,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php",
            "line": 41,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Routing\\Middleware\\SubstituteBindings",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php",
            "line": 59,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Routing\\Middleware\\ThrottleRequests",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 105,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 683,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 658,
            "function": "runRouteWithinStack",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 624,
            "function": "runRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 613,
            "function": "dispatchToRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 170,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 130,
            "function": "Illuminate\\Foundation\\Http\\{closure}",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
            "line": 21,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
            "line": 21,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php",
            "line": 27,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php",
            "line": 63,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/fideloper/proxy/src/TrustProxies.php",
            "line": 57,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Fideloper\\Proxy\\TrustProxies",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 105,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 145,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 110,
            "function": "sendRequestThroughRouter",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/public/index.php",
            "line": 55,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/home/ixi/Desktop/TuniSales/Dev/v1.0.0/server.php",
            "line": 21,
            "function": "require_once"
        }
    ]
}
alok20100 commented 4 years ago

i too, getting same error, if any one know how to fix it, help us

chris-redbeed commented 4 years ago

You can use my Fork/PR (#37)

alok20100 commented 4 years ago

You can use my Fork/PR (#37)

after added confidential() METHOD IN cLIENT.PHP FILE ITS getting new error

Client error: POST http://consumer.com/oauth/token resulted in a 400 Bad Request response:\n {"error":"invalid_request","error_description":"The request is missing a required parameter, includes an invalid paramet (truncated...)\n