Hello!
There was such a problem, you need to implement cross domain authentication.
The scheme is as follows:
1. On the first domain (user.mysite.com) there is a user's personal account that works on yii2 and through which the authorization will take place.
2. On the second domain (mysite.com) there is an online store on a "samopisny" engine that should work with an authorized user.
3. DB they have one.
4. They lie on the same server in neighboring directories.
5. the "remember me" option should be implemented

Can you make it work? And how best to do it?

  • four
    You wrote a TOR for freelancing, and not a question for SO, didn’t Google find a single solution that you could try to make and write here what exactly didn’t work? - MasterAlex
  • one
    why it is impossible to wrap everything through one database (localhost) and in the right places poke redirects to the right site? - Vyacheslav Potseluyko

2 answers 2

In config

'user' => [ 'identityClass' => 'common\models\User', 'enableAutoLogin' => true, 'identityCookie' => [ 'name' => '_identity', 'httpOnly' => true, 'domain' => '.' . DOMAIN, ], ], 'session' => [ 'cookieParams' => [ 'domain' => '.' . DOMAIN, 'httpOnly' => true, ], ], 

In index.php

 defined('DOMAIN') or define('DOMAIN', 'mysite.com'); 

Cookies will be common to the domain and subdomains

    It is necessary that both domains match

    1. authentication class, probably it is, if the native mechanisms Yii are used;
    2. the domain where the authentication cookie is stored. in the site settings on the sub-domain, specify the parent domain;
    3. base with user accounts. You said that the database is total - approx.

    Just in case, I will say:
    Do not test this on the localhost domain. Browsers are freaking out with cookies on the first level domains. If you need to try it locally, get a synonym for localhost, such as localhost.com , in hosts.
    Pay attention in the settings to the dot in front of the domain name, this is the canonical form!

    Cm.
    http://yiiframework.ru/doc/cookbook/ru/install.cookie.subdomains
    https://stackoverflow.com/questions/29378697/automagically-log-into-multiple-domains-in-yii2