public function signIn(Request $request)
    {
        $oauth_client = DB::table('oauth_clients')->where('password_client', 1)->first();

        if (!$oauth_client) {
            return $this->response([
                'code' => 'CLIENT_NOT_FOUND',
            ], Response::HTTP_BAD_REQUEST);
        }

        $request->request->add([
            'username'      => $request->input('username'),
            'password'      => $request->input('password'),
            'scope'         => '*',
            'grant_type'    => 'password',
            'client_id'     => $oauth_client->id,
            'client_secret' => $oauth_client->secret,
        ]);
        $request = Request::create('/oauth/token', 'POST', []);

        $response = Route::dispatch($request);

        $body = json_decode($response->getContent());

        if ($response->getStatusCode() === 200) {
            return $this->response(['data' => $body], Response::HTTP_OK);
        }

        if ($response->getStatusCode() === 401) {
            return $this->response(['errors' => ['code' => 'NOT_VALID', 'message' => $body->error]], Response::HTTP_UNAUTHORIZED);
        }

        if ($response->getStatusCode() === 400) {
            return $this->response(['errors' => ['code' => 'BAD_REQUEST', 'message' => $body->message]], Response::HTTP_BAD_REQUEST);
        }
    }
public function signIn(Request $request)
    {
        $oauth_client = DB::table('oauth_clients')->where('password_client', 1)->first();

        if (!$oauth_client) {
            return $this->response([
                'code' => 'CLIENT_NOT_FOUND',
            ], Response::HTTP_BAD_REQUEST);
        }

        $request->request->add([
            'username'      => $request->input('username'),
            'password'      => $request->input('password'),
            'scope'         => '*',
            'grant_type'    => 'password',
            'client_id'     => $oauth_client->id,
            'client_secret' => $oauth_client->secret,
        ]);
        $request = Request::create('/oauth/token', 'POST', []);

        $response = Route::dispatch($request);

        $body = json_decode($response->getContent());

        if ($response->getStatusCode() === 200) {
            return $this->response(['data' => $body], Response::HTTP_OK);
        }

        if ($response->getStatusCode() === 401) {
            return $this->response(['errors' => ['code' => 'NOT_VALID', 'message' => $body->error]], Response::HTTP_UNAUTHORIZED);
        }

        if ($response->getStatusCode() === 400) {
            return $this->response(['errors' => ['code' => 'BAD_REQUEST', 'message' => $body->message]], Response::HTTP_BAD_REQUEST);
        }
    }
public function signIn ( Request $ request ) { $ oauth_client = DB :: table ( 'oauth_clients' ) -> where ( 'password_client' , 1 ) -> first ( ) ; if ( ! $ oauth_client ) { return $ this -> response ( [ 'code' => 'CLIENT_NOT_FOUND' , ] , Response :: HTTP_BAD_REQUEST ) ; } $ request -> request -> add ( [ 'username' => $ request -> input ( 'username' ) , 'password' => $ request -> input ( 'password' ) , 'scope' => '*' , 'grant_type' => 'password' , 'client_id' => $ oauth_client -> id , 'client_secret' => $ oauth_client -> secret , ] ) ; $ request = Request :: create ( '/oauth/token' , 'POST' , [ ] ) ; $ response = Route :: dispatch ( $ request ) ; $ body = json_decode ( $ response -> getContent ( ) ) ; if ( $ response -> getStatusCode ( ) === 200 ) { return $ this -> response ( [ 'data' => $ body ] , Response :: HTTP_OK ) ; } if ( $ response -> getStatusCode ( ) === 401 ) { return $ this -> response ( [ 'errors' => [ 'code' => 'NOT_VALID' , 'message' => $ body -> error ] ] , Response :: HTTP_UNAUTHORIZED ) ; } if ( $ response -> getStatusCode ( ) === 400 ) { return $ this -> response ( [ 'errors' => [ 'code' => 'BAD_REQUEST' , 'message' => $ body -> message ] ] , Response :: HTTP_BAD_REQUEST ) ; } }
Sign in a user.

@param \Illuminate\Http\Request $request

@return \Symfony\Component\HttpFoundation\Response
Sign in a user .