This article describes the SSO single sign-on system access function implemented by PHP. Share to everyone for your reference, specific as follows:
SSO English full name single Sign on, point login. SSO is a multiple application system in which users can access all trusted applications with only one login. It includes a mechanism to map this primary login to other applications for the same user's login. It is one of the most popular solutions for enterprise business integration, so let's take a look at it.
Simple talk about SSO single sign-on system of the principle of access, the premise is that the system itself has a sound user authentication function, that is, the basic user login function, it is very convenient to do.
SSO Login Request interface is often the interface plus a callback address, access to this address will jump to the callback address and take a ticket parameter, holding this ticket parameter request interface can obtain the user information, if there is a user automatically login, there is no new user and login.
For example, this SSO model implements two methods, one is to get the interface URL, one is to get the user information by ticket:
Interface Ssologin
{
/**
* Obtain login user Information
* @param $ticket
* @return Mixed
* * Public function Getinfofromticket ($ticket);
/**
* Single sign-on license address
* @return mixed
/public
function Getauthurl ();
}
Then look at the main method of the controller, such as the callback address is to jump to the controller http://www.example.com/sso/check?ticket=xxxx
/** * Detect if single sign-on * @return bool|string */Public Function ACTIONCheck () {$ticket = Yii:: $app->getrequest ()->get
(' ticket '); if (! $ticket) {return $this->renderautherror (' Please authorize first ', sprintf (' <a href= '%s ' > click Login Single sign-on system </a> ', Ssologin:
: getinstance ()->getauthurl ());
$userInfo = Ssologin::getinstance ()->getinfofromticket ($ticket); if (Empty ($userInfo [' username ']) {return $this->renderautherror (' Authorize first ', sprintf (' <a href= '%s ' > click Login Single sign-on system &
Lt;/a> ', Ssologin::getinstance ()->getauthurl ()));
$username = $this->getusername ($userInfo [' username ']);
$user = User::find ()->canlogin ()->username ($username)->one ();
if (! $user) {$newUser = [];
$newUser [' username '] = $userInfo [' username '];
$newUser [' email '] = $this->getusername ($userInfo [' username ']);
$newUser [' role '] = User::role_dev;
$newUser [' is_email_verified '] = 1;
$newUser [' realname '] = $userInfo [' Truename ']; $user = $this->adduser ($newUsER);
$isLogin = Yii:: $app->user->login ($user, 3600 * 24 * 30);
if ($isLogin) {$this->redirect ('/task/index ');
return true;
}
Probably see the logic of this controller. The SSO interface plays a role in obtaining the user information, comparing the user information with the System User table, the user is logged in, there is no creation user and login.
This is an internal single point system, integrated into the background, perhaps other SSO is not the same as this, but the basic principle process is similar.
More interested in PHP related content readers can view the site topics: "PHP Network Programming Skills Summary", "Php Curl Usage Summary", "PHP Socket Usage Summary", "PHP Regular Expression Usage summary", "PHP string (String) Usage Summary", " PHP array Operation techniques Encyclopedia, "PHP Mathematical Calculation Skills Summary", "PHP object-oriented Programming Introductory Course", "PHP Data structure and algorithm tutorial", "PHP Programming algorithm Summary" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design.