Laravel mailgun driver ignores verified domain and uses sandbox instead - laravel-5

I'm trying to use mailgun to send notifications to users. I have verified domain, but even though my config\services.php file looks like this:
'mailgun' => [
'domain' => 'mg.mydomain.biz',
'secret' => 'key-3223423423n423j42jklkj23l',
],
all the emails go through sandbox domain.
php artisan config:clear does not help. It is the same with development and production environment. Also I need to point out that emails come from #maydomain.biz when config\mail.php clearly states 'from' => ['address' => 'no-reply#mg.mydomain.biz', 'name' => 'Sender'],. I channged it hours ago and cleared config cache un restarted web server since.

sudo service supervisor restart solved the problem.

Related

Laravel 6 with laravel passport, weird Guzzle error

I have followed the instructions for installing a password client for Laravel passport exactly as written in the Laravel docs and with default Laravel 6.0 composer versions of guzzle, etc. I have done the install on an existing project and as a clean install, both on local dev environment and live server, and every time I try to post to the example.com/oauth/token route, I am greeted with a crazy Guzzle error that seems to have no previous search history on the internet. The error is (summarized):
GuzzleHttp\Exception\ServerException
/var/task/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
"Return value of Zend\\Diactoros\\normalizeServer() must be of the type array, none returned"
I am running php 7.3 in all environments, but tried php 7.2 and 7.1 and got the same result. I'm running Laravel Valet locally, and have never seen anything like this on any other project. I am also running a staging server with Laravel Vapor, and I get the exact same error. My guzzle request is almost exactly the same as Taylor Otwell's example in the Laravel docs, and looks like this:
$http = new \GuzzleHttp\Client;
$response = $http->post(env('API_TOKEN_URL'), [
'form_params' => [
'grant_type' => 'password',
'client_id' => env('PASSPORT_CLIENT_ID'),
'client_secret' => env('PASSPORT_CLIENT_SECRET'),
'username' => $request['username'],
'password' => $request['password'],
],
]);
return json_decode((string) $response->getBody(), true);
I have data dumped all variables to verify that the username, password, client_id and client_secret are all accurate. It doesn't seem to be an authentication issue at all, but some issue with Guzzle passing proper server headers. I have no idea how to fix, as there is no previous record of this issue that I could find anywhere else on the internet. Any ideas???
if someone face this issue just update the package name: laminas/laminas-diactoros to latest version such as 2.2.2 by running
composer require laminas/laminas-diactoros
the problem comes from
normalize_server.legacy.php
its does not return anything.

Pusher: Error: Invalid key in subscription auth data:

I want to create a collaborative text editor app and came across this tutorial. I accessed the repository on github and followed all the steps from the README file to install and use the app. Also, in the tutorial, after I created the app on Pusher, I checked the "Enable client events" option on the App Settings tab.
However, when I type anything in the note textfield, the two following errors appear on the browser's console:
1)
Pusher : Error : {"type":"WebSocketError","error":"type":"PusherError","data":
{"code":null,"message":"Invalid key in subscription auth data:
'xxxxxxxxxxxx'"}}}
2)
Pusher : Error : {"type":"WebSocketError","error":
{"type":"PusherError","data":{"code":null,"message":"Cannot broadcast
client event (connection not subscribed to channel presence-note.note-
test-for-pusherqjvQbgt4s9)"}}}
The second error happens when I type something and the first one right when I load the page. I presume the second one is happening because of the first one.
This is my broadcasting.php file:
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
//
'cluster' => 'us2',
'encrypted' => true
],
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
'log' => [
'driver' => 'log',
],
'null' => [
'driver' => 'null',
],
],
The values set in the env file I get from the app keys on my Pusher account. I've already double checked if the values are set correctly and it seems to be fine.
I appreciate any help. Thanks in advance
The first client side error suggests your auth endpoint isn't sending a valid response to the client, and Pusher can't validate it. Have you specified exactly the same credentials in your server as in your client? Especially the specification of the cluster.
The second client side error you're getting suggests that your client hasn't actually subscribed to the channel, which would mean that client events wouldn't work.
Double check your client side code to make sure it is actually subscribing to the channel in question. Also, double check the app settings in your Pusher dashboard to ensure client events are enabled.
Perhaps it would be helpful to enable logging on your client side Pusher object. See https://github.com/pusher/pusher-js#global-configuration
We've had the same issue and solved it for Laravel + Vue.
The problem was that the front-end developer is using another Pusher account for local development and he is sending compiled front-end files to git repo.
So, when I get the compiled js files, Echo is created with different credentials than mine because in my .env file there are my Pusher channel credentials.
Solution: npm run dev on my machine. (So that it compiles the js files and Echo will be created with my .env Pusher credentials)
P.S. This solution affirms answer of #kn100
Following steps work for me
Check your app keys at server and client side
run php artisan config:cache
run ``php artisan optimize:clear`
run composer dump-autoload
Restart your IDE
Test your app

Session not persisting on shared hosting - Laravel 4.2.17

I have a problem with the sessions on the shared hosting.
I developed an app on a local server (XAMPP) and it works great (sessions, auth etc). The problems have appeared when I moved the app on a shared hosting.
I realized that the sessions are not persisting from a page to another or from AJAX files to another page and the Authentication does not work either .
The only session that persists is the _token which has a different value after every refresh of the page.
I have the following configuration in the session.php file:
'driver' => 'database',
'lifetime' => 120,
'expire_on_close' => false,
'lottery' => array(2, 100),
'path' => '/',
'domain' => null
First, I used file driver and I had the same problem, and now I used the database.
Both file and database work on the local server but on the shared hosting they do not.
I tried all the solutions found on the forum but still I have the same problem.
I think the problem is at the session domain setting because when I change the value from null to other string on my local server, I have the same problem that I have encountered online.
Can you help me, please!
Thanks, Mirel
I fixed the problem. In my case the error because I have added a php closed tag ?> in the end of the included files. So removing this tag will bring the application back to normal behavior.

Persisting sessions across subdomains in Laravel 5

Using 5.0
in config/session.php I have set 'domain' => '.example.com' but it is not working. I cannot persist a session on even one domain like this.
My site has many subdomains:
vancouver.example.com
newyork.example.com
etc... they are hosted on the same server and are the same Laravel app (share the same storage directory)
I login with the correct credentials, upon which the app redirects to another page on the site, and I have no session at that point. var_dump(Auth::user()) shows null even though I logged in with the correct credentials.
storage/framework/sessions shows 14 different files there, they are all for me and I cleared them out before I started testing this.
I'll attach my AuthController#postLogin method below, which works fine if session.php 'domain' => null
public function postLogin(Request $request)
{
$this->validate($request, [
'email' => 'required|email', 'password' => 'required',
]);
$credentials = $request->only('email', 'password');
if ($this->auth->attempt($credentials, $request->has('remember'))) {
Session::flash('message', 'You are now logged in.');
Session::flash('status', 'success');
if (str_contains($_SERVER['HTTP_REFERER'], '?goto=')) {
$params = explode('?', $_SERVER['HTTP_REFERER'])[1];
$target = explode('=', $params)[1];
} else {
$target = '/';
}
return redirect($target);
}
return redirect($this->loginPath())
->withInput($request->only('email', 'remember'))
->withErrors([
'email' => $this->getFailedLoginMessage(),
]);
}
Figured it out. Update domain => '.example.com' in session.php and clear the cookies for the site in question.
#gadss
you need to add session table like this
php artisan session:table
composer dump-autoload
php artisan migrate
and change .env to
SESSION_DRIVER=database
also modify config/session.php
'driver' => env('SESSION_DRIVER', 'database') and
'domain' => '.yourdomain.com'
after that clear your browser's cache and cookies.
You'll need to update the session configuration to persist the session in domain-wide including subdomains. Follow the steps given below.
Go to config/session.php and update the domain with prefix . as config => '.your-domain.com'.
Then clear your application cache, Open the Chrome DevTool and Go to Application > Application > Clear Storage. You'll need to clear out the previous cookies also.
run artisan command php artisan config:cache or php artisan config:clear to drop previously cached laravel application configs.
If you are using database as the session driver, You need to create a session table for that. run command php artisan session:table to generate the session table migration and then migrate it using php artisan migrate. Then perform the three steps given above.
With Laravel 8 it becomes more simplier :
Add SESSION_DOMAIN to your .env file :
SESSION_DOMAIN=.yourdomain.tld
Clear configuration cache :
php artisan config:cache
Delete your browser sessions cookies, then session become shared between all your subdomains.
In my case I used to AutoLogin user to subdomain once account is created on www. domain. Worked fine.
Have you tried storing the sessions in the database, memcached, or redis instead of in files? I had a similar situation to yours and storing sessions in the database solved the issue for me.
For some reason Laravel's session driver doesn't handle cross domain sessions correctly when using the file driver.
If someone still gets the problem with subdomain cookie. Try to change Session Cookie Name in config/session.php
If someone needs to sync session in subdomains with different laravel application sharing same database
Follow all the instructions of #Kiran Maniya
Then you have to keep same application name in order to get same session name. Or just change the cookie config in config/session.php
You can hardcode it if keeping same name is not possible.
'cookie' => env(
'SESSION_COOKIE',
Str::slug(env('APP_NAME', 'laravel'), '_').'_session'
)
to something like:
'cookie' => env(
'SESSION_COOKIE',
'session_sharing_application_session'
)

Laravel 4.1 session variables getting randomly forgotten

I'm using a Laravel 4.1 app on Apache, and everything is working fine on my local dev machine, but on my staging machine (which is on a shared host) users are randomly getting logged out and prompted to enter their credentials again.
The relevant settings:
app/config/session.php:
<?php
return array(
'driver' => 'file',
'lifetime' => 120,
'expire_on_close' => true,
'files' => storage_path().'/sessions',
'connection' => null,
'table' => 'sessions',
'lottery' => array(2, 100),
'cookie' => 'laravel_session',
'path' => '/',
'domain' => null,
'secure' => false,
);
using Laravel's default authentication driver
php.ini:
gc_maxlifetime=1440
gc_probability=1
gc_divisor=100
This does not seem to be the same as the issue some others have experienced here. The session file is not getting cleared by php. Just a few of the session variables are getting dropped randomly.
I tail -F'd the session file and could see when the variables are getting dropped between one request and the next. It looks like this (formatted for easier reading) before:
a:4:{
s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}
s:6:"_token";s:40:"hvuw9VWWjssSwUL2C5eVSn0qZ2g1cwVF5YCEsLG7";
s:38:"login_82e5d2c56bdd0811318f0cf078b78bfc";i:2;
s:9:"_sf2_meta";a:3:{s:1:"u";i:1399318721;s:1:"c";i:1399318011;s:1:"l";s:1:"0";}}
and after:
a:3:{
s:6:"_token";s:40:"7o3b6NhiuDKXq4ftvngUefqe6cWybX1tzPEcDaxk";
s:9:"_sf2_meta";a:3:{s:1:"u";i:1399318721;s:1:"c";i:1399318721;s:1:"l";s:1:"0";}
s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}
The login_ session is gone, which results in Laravel's Session class assuming the user is not authenticated. I am not sure why this session variable is getting dropped, though. None of Session::forget, ::clear(), ::remove() or ::invalidate() are being called on the login session variable as far as I can tell.
I also noticed that the _token variable is constant between requests until the moment when the issue arises at which point it changes, as you can see above.
Any idea what's going on here?
Switching to the database session manager seems to have solved the problem. I suspect that there was some way on my host server configuration that php was wiping out the session files.

Resources