aclavijo/cakeopenidconnect

为 cake php 1.3 提供Google OpenId Connect功能

v0.1.15 2017-09-25 12:37 UTC

README

本插件为 cake 1.3 框架提供 Google OpenId Connect。

我尽量使安装简单。所以请阅读安装部分 :)

依赖项

本项目包含一个依赖项

  • "google/apiclient": "^2.0" '文档'
  • "symfony/yaml" : "3.1.*" '文档'
  • "aclavijo/cakephp-installer-plugin": "0.1.*" 自定义 composer 安装器

安装

通过 composer

composer require aclavijo/cakeopenidconnect

安装完成后,composer 将将插件放置在 'app/plugins/openid' 目录下

Parameter.yml

您需要从 parameter.yml.dist 创建一个 parameter.yml 文件,位于 app/plugins/openid/config 下

配置

#parameters.yml
OpenidConnect:
    client_id: string
    secret_id: string
    scopes: array
    #optionnal
    domains: null|array #default null
    log_path: null|array #default null
    cake_log: false|true #default true
    flash_ctp: string #default flash_bas
  • client_id: 由 google 提供的 client_id
  • secret_id: 由 google 提供的 client_id
  • scopes: google openid 范围 ['openid', 'email', 'profile'] 最小 ['openid', 'email']
  • domains: 如果您只想通过电子邮件地址域名进行认证(其他将被拒绝),则为数组
  • log_path: 指定另一个日志文件路径(例如 Apache)
  • cake_log: false 以禁用 cake 日志
  • flash_ctp: 要显示错误登录消息的 cake 1.3 flash 模板名称

将其部署到您的项目中

用户搜索功能

  • app/models/uilisateur.php 中,添加以下函数
    function getUserByPseudo($pseudo)
    {
        $params = array(
            'conditions' => array('Utilisateur.pseudo' => $pseudo)
        );
        $result = $this->find('first', $params);
        
        return $result['Utilisateur'];
    }

(可选) 添加路由到路由器

  • 在文件 app/config/router.php
Router::connect('/openid/oauth/authentification', array('plugin' => 'openid', 'controller' => 'oauth', 'action' => 'authentification'));

添加连接链接

  • login.ctp
 echo $html->link('Name your button', array(
        'plugin' => 'openid', 
        'controller' => 'oauth',
        'action' => 'authentification' 
    ), array(
        'class' => 'btn btn-primary'
    )); ?>

待办事项

  • 实现 log_path 功能