Can't make http POST request on laravel application - php

When i try to send http POST request to get passport token ,that request cannot processed.
$response = Http::asForm()->post('http://localhost:8000/oauth/token', [
'grant_type' => 'password',
'client_id' => env('PASSPORT_CLIENT_ID', null),
'client_secret' => env('PASSPORT_CLIENT_SECRET', null),
'username' => $request->email,
'password' => $request->password,
'scope' => '',
]);
return $response->json();
My project run on port 8000. But I am not able to make a http post request using port 8000 .
Instead of that I need to run same project on 8000 and 8001 to get result.
$response = Http::asForm()->post('http://localhost:8001/oauth/token', [
'grant_type' => 'password',
'client_id' => env('PASSPORT_CLIENT_ID', null),
'client_secret' => env('PASSPORT_CLIENT_SECRET', null),
'username' => $request->email,
'password' => $request->password,
'scope' => '',
]);
return $response->json();
This will return expected output. But I need expected output by running my project only on single port. Someone please help me.

Related

Laravel 8 - unsupported_grant_type

I have a problem with the following:
I am creating an API (I'm new with this)
With this API I want to consume another API or WebService
In Postman I make a get request to the URL and it returns OK the access_token, but in the Laravel project it returns: "error" => "unsupported_grant_type".
This is my code:
use Illuminate\Support\Facades\Http;
$response = Http::withHeaders([
'content-type' => 'application/x-www-form-urlencoded'
])->post('http://url:52904/Token', [
'userName' => 'menganito',
'password' => 'pepito',
'grant_type' => 'password'
]);
dd($response->json());
I tried installing ** Laravel Passport **, but I'm not using a DB for now.
The problem was x-www-form-urlencoded.
This solved my problem (asForm)
$response = Http::asForm()->post('http://url.com', [
'userName' => 'user',
'password' => 'pass',
'grant_type' => 'password'
]);
dd($response->json());

How to move file to other server in Laravel using ftp and private key?

i want to move file from my site to other server using ftp in laravel.
i put this setting in config/filesystem.php and its works
'ftp' => [
'driver' => 'ftp',
'host' => 'ftp.xxx.my',
'username' => 'xxx',
'password' => 'xxx',
'root' => '/tess',
],
But my client ask to use private key only without password and username, so i changed my setting
'ftp' => [
'driver' => 'ftp',
'host' => 'ftp.xxx.my',
'privateKey' =>storage_path('app/public/key/momuat.ppk'),
'root' => '/tess',
],
and i got error
Could not login with username: anonymous, host: 192.168.0.123
Please help me

Send Email from SMTP remote server CakePHP 3

I'm facing some problems configuring my app to send Mails from my smtp server, which is located in one remote hosting with 1and1.
I don't know if I'm missing something:
I've changed my app.php to the values given by my hosting provider:
'EmailTransport' => [
'default' => [
'className' => 'Mail',
'host' => 'smtp.1and1.com',
'port' =>'587' ,
'timeout' => 30,
'username' => 'me#dns.com',
'password' => '******',
'client' => null,
'tls' => null,
],
],
'Email' => [
'default' => [
'transport' => 'default',
'from' => '#localhost',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
],
],
Here you can see the instructions given by my hosting provider to connect to their smtp server.
I don't get any result.
Does anybody have an Idea what may I be missing?
I got it working setting classname as 'Mail' and the rest of the parameters as default. Please, do as follows:
'EmailTransport' => [
'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null,
],
],
In my case only was problem in className.
For using gmail or office365 server it should be so:
'EmailTransport' => [
'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'smtp.office365.com',
'port' => 587,
'timeout' => 30,
'username' => 'my#email.com',
'password' => 'myPassword',
'client' => null,
'tls' => true,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
],
Please do as following:
//Adding Smtp information for sending mail through smtp instead of php mail function on local server / live server
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
'host' => 'smtp.1and1.com',
'port' =>'587' ,
'timeout' => 30,
'username' => 'me#dns.com',
'password' => '******',
'client' => null,
'tls' => null,
],
],
You can also enable tls to 'tls' => true if required.

Email sending in Laravel5

I want to send email from my localhost in laravel 5 using driver: smtp and host: smtp.gmail.com
here is my sample code for sending email after successful account open.
public function postRegister(Request $request)
{
$password = PropertyHelper::randomPassword();
$arrUser = [
'_token' => $request->input('_token'),
'name' => $request->input('name'),
'mobile' => $request->input('mobile'),
'email' => $request->input('email'),
'password' => $password,
'password_confirmation' => $password
];
$validator = $this->registrar->validator($arrUser);
if ($validator->fails())
{
$this->throwValidationException(
$request, $validator
);
}
$data = [
'name' => $request->input('name'),
'password' => $password,
'email' => $request->input('email'),
];
$this->auth->login($this->registrar->create($arrUser));
$data = [
'name' => $request->input('name'),
'password' => $password,
];
$emailSend = Mail::send('emails.signup', $data, function($message){
$message->to(Auth::user()->email)
->subject('নতুন একাউন্ট');
});
dd($emailSend); //output 1
if($emailSend)
{
return redirect($this->redirectPath());
}
}
Here is my config/mail.php file
return [
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => ['address' => 'hizbul25#gmail.com', 'name' => 'Admin'],
'encryption' => 'tls',
'username' => 'myEmail#gmail.com',
'password' => 'gmailPassword',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
];
This code did not show any error but not also send email. If i try to print the out of email send it says 1. Any idea please ??
try to change the mail info inside .inv under root folder instead of mail.php as previous versions of laravel

Rocketeer. How can I execute commands on different servers after deploying?

I have several servers - backend, frontend and api.
To deploy the code on the servers I use Rocketeer.
I use multiple servers for one connection:
'connections' => array(
'production' => array(
'servers' => array(
array(
'host' => 'xxx.xxx.xxx.xxx', // backend
'username' => 'admin',
'password' => 'xxxxxx',
'key' => '',
'keyphrase' => '',
),
array(
'host' => 'xxx.xxx.xxx.xxx', // api
'username' => 'admin',
'password' => 'xxxxxx',
'key' => '',
'keyphrase' => '',
),
array(
'host' => 'xxx.xxx.xxx.xxx', // frontend
'username' => 'admin',
'password' => 'xxxxxx',
'key' => '',
'keyphrase' => '',
),
),
),
).
For each server performs its tasks.
To determine the current connection, I use the following code in hooks.php
$connection = $task->getConnection();
$server = $connection->connections->getServer();
$credentials = $connection->connections->getServerCredentials($connection->connections->getConnection(), $server);
switch($credentials['host']){
case 'xxx.xxx.xxx.xxx':
$task->runForCurrentRelease('...');
break;
}
The data are uploaded to servers sequentially.
After deploying to last server I can't execute command on previous servers.
How can I execute commands on different servers after deploying? (for example: restart nginx, restart memcached etc.)
I believe this is what you're looking for: http://rocketeer.autopergamene.eu/#/docs/docs/II-Concepts/Events
You should be able to create your own listener for each set of commands.

Categories