fabian/linkedin-nette

Nette框架的LinkedIn授权

dev-master 2014-10-21 19:15 UTC

This package is not auto-updated.

Last update: 2024-09-14 15:00:52 UTC


README

最佳方式是通过Composer

composer require fabian/linkedin-nette:dev-master

使用方法

linkedin:
    appId: "YOUR_API_KEY"
    appSecret: "YOUR_API_SECRET"
    permissions: [r_fullprofile, r_emailaddress]

和扩展

extensions:
    linkedin: \Fabian\Linkedin\LinkedinExtension
  • 在您的BasePresenter中注入LinkedIn扩展
/**
 * @var \Fabian\Linkedin\Linkedin
 */
private $linkedin;

public function __construct(\Fabian\Linkedin\Linkedin $linkedin)
{
    parent::__construct();
    $this->linkedin = $linkedin;
}
  • 并创建处理登录操作组件
protected function createComponentLinkedinLogin()
{
    $dialog = $this->linkedin->createDialog();
    /** @var \Fabian\Linkedin\LoginDialog $dialog */
    
    $dialog->onResponse[] = function(\Fabian\Linkedin\LoginDialog $dialog) {
        $me = $this->linkedin->call(
            'people/~:(id,first-name,last-name,email-address)'
        );
        
        // if user is not found in your database, register new based on LinkedIn profile details
        if (!$existing = $this->usersModel->findByLinkedinId($me->id)) {
            $existing = $this->usersModel->registerFromLinkedin((array) $me);
        }

        $this->user->login(new \Nette\Security\Identity($existing->users_id, $existing->role, $existing));
    };
    
    return $dialog;
}
  • 将LinkedIn登录放在您的模板中
<a n:href="linkedinLogin-open!">Login by LinkedIn</a>

Kdyby\Facebook启发