Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set cookie #13

Open
bcarl314 opened this issue Oct 17, 2019 · 2 comments
Open

Unable to set cookie #13

bcarl314 opened this issue Oct 17, 2019 · 2 comments
Labels

Comments

@bcarl314
Copy link

bcarl314 commented Oct 17, 2019

I have tried to install this plugin, but do not see any cookies getting set. Below is the setup I'm using:

In src/Controller/AppController.php

`
$this->loadComponent('Auth',[

	 'loginRedirect' => [
		    'controller' => 'Users',
		    'action' => 'dashboard'
	    ],
	    'logoutRedirect' => [
		    'controller' => 'Users',
		    'action' => 'login'
	    ],
	    'authenticate' => [
		    'RememberMe.Cookie' => [
			    'userModel' => 'Users',
			    'fields' => ['username' => 'email', 'password' => 'password'],
			    'inputKey' => 'remember_me',
			    'always' => true,
			    'cookie' => [
				    'name' => 'rememberMe',
				    'expires' => '+90 days',
				    'secure' => true,
				    'httpOnly' => true,
			    ],
		    ],
		    'Form' => [
			    'fields' => ['username' => 'email', 'password' => 'password']
		    ]
	    ]
    ]);

`

In src/Template/Users/login.ctp

`

Form->create() ?>
<fieldset>
	<legend><?= __('Please enter your username and password') ?></legend>
	<?= $this->Form->control('email') ?>
	<?= $this->Form->control('password') ?>
	<?= $this->Form->control('remember_me', ['type' => 'checkbox']) ?>
</fieldset>
<br />
<?= $this->Form->button(__('Login'), ['class' => 'btn btn-success']); ?>


<?= $this->Form->end() ?>

`

When I login (and check the remember me checkbox, I see a new token in the remember_me_tokens with the foreign_id matching my user_id. However, when I examine the cookies, I see nothing set other than the csrfToken.

I must be missing something obvious here, but not seeing it.

CakePHP 3.7 on PHP 7.0.33

@bcarl314 bcarl314 changed the title Unable to get cookie set Unable to set cookie Oct 17, 2019
@nojimage
Copy link
Owner

Are you using over https connection? please try, 'secure' => false, if connection is http.

@hacheraw
Copy link

hacheraw commented Mar 12, 2020

I have the same issue. CakePHP 3.8 (localhost, no https)

$this->loadComponent('Auth', [
    'authenticate' => [
        'RememberMe.Cookie' => [
            'userModel' => 'Users',
            'fields' => ['username' => 'email', 'password' => 'password'],
            'inputKey' => 'remember_me',
            'secure' => false, //tried this
            'always' => true //and this
        ],
        'Form' => [
            'fields' => [
                'username' => 'email',
                'password' => 'password'
            ]
        ]
    ],
    'loginAction' => [
        'controller' => 'Users',
        'action' => 'login'
    ],
    // If unauthorized, return them to page they were just on
    'unauthorizedRedirect' => $this->referer()
]);

Tokens are being saved:

image

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants