Search code examples
phplaravellaravel-passport

Laravel Passport - Get Client Secret by client id


I have the client_id from oauth_clients and need to get the secret. Not possible to make a normal Model query or DB query, since the secret property is protected.


Solution

  • You can access the client_id and client_secret if you know the oauth_clients id:

    /**
         * DefaultController constructor.
         */
        public function __construct()
        {
            $this->client = DB::table('oauth_clients')->where('id', 2)->first();
        }
    
        /**
         * @param Request $request
         * @return mixed
         */
        protected function authenticate(Request $request)
        {
            $request->request->add([
                'username' => $request->username,
                'password' => $request->password,
                'grant_type' => 'password',
                'client_id' => $this->client->id,
                'client_secret' => $this->client->secret,
                'scope' => '*'
            ]);
    
            $proxy = Request::create(
                'oauth/token',
                'POST'
            );
    
            return Route::dispatch($proxy);
        }