承接 moz-morris/cakephp-facebook-auth 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

moz-morris/cakephp-facebook-auth

Composer 安装命令:

composer require moz-morris/cakephp-facebook-auth

包简介

Facebook authentication handler for CakePHP 2.0

README 文档

README

The purpose of the Facebook Authentication Handler is to provide Facebook Authentication for your CakePHP 2.0 or later based application. The handler has been built following Cake's recommended approach for building custom authentication objects for use with the built in AuthComponent. The handler itself is part a FacebookAuth plugin, though this is essentially to make the handler easily redistributable with example configuration settings and an example controller detailing a typical use case scenario.

It should be noted that though this handler stores the access token returned by Facebook, it does not currently provide a means to makes calls to the Graph API. It's function is to provide authentication. Of course, you could use the access token and your preferred method to communicate with Facebook.

Changelog

  • 1.0 Sharing it with the world for the very first time.
  • 1.1 Add email & name fields by default & ensure handler uses configuration settings

Installation

Get the code

Via Git

First clone the repository into a new app/Plugin/FacebookAuth directory

git clone git://github.com/MozMorris/FacebookAuthenticate-CakePhp-Authentication-Handler.git /path/to/your/app/Plugin/FacebookAuth

Via Composer

Add a dependency to your composer.json file. (Looks like the CakePHP convention is to have the composer.json file located under app/)

"require": {
  "moz-morris/cakephp-facebook-auth": "dev-master"
}

Then composer install or composer update. You might need to add "minimum-stability": "dev" to you composer.json file.

Facebook Application & App Configuration

  1. Rename the example configuration FacebookConfig.ini.example to FacebookConfig.ini. It can be found under app/Plugin/FacebookAuth/Config/
  2. Head on over to the Facebook Developer App and either setup a new application to get a App ID/API Key & App Secret, or note down the ones from your existing app. NOTE: Your 'App Domain' must be the same host as you're accessing your site with to enable Auth. Otherwise, when you attempt to authenticate, Facebook will return "API Error Code: 191 | API Error Description: The specified URL is not owned by the application | Error Message: Invalid redirect_uri: Given URL is not allowed by the Application configuration."
  3. Update your FacebookConfig.ini with the App ID/API Key & App Secret.
  4. Load the plugin and it's configuration in your bootstrap file app/Config/bootstrap.php
  5. Configure the FacebookAuth handler at runtime

Loading the plugin and configuration (bootstrap.php):

/**
 * Load custom configuration files using the IniReader class
 */
App::uses('IniReader', 'Configure');
Configure::config('default', new IniReader(APP . 'Plugin' . DS . 'FacebookAuth' . DS . 'Config' . DS));
Configure::load('FacebookConfig', 'default');

/**
 * Load Facebook Plugin
 */
CakePlugin::load('FacebookAuth');

Configuring the handler at runtime:

public function beforeFilter()
{
  parent::beforeFilter();

  /**
   * Configure FacebookAuth handler
   */
  $this->Auth->authenticate['FacebookAuth.Facebook']['application'] = array(
   'id'     => Configure::read('facebook.app_id'),
   'secret' => Configure::read('facebook.app_secret')
  );
}

Database

Add email, name, facebook_user_id, facebook_access_token fields to your User model. In this example we're adding the fields to the users table which is pretty much the standard for Cake apps using some kind of user authentication. If your app is slightly different, then make the relevant changes.

ALTER TABLE `users` ADD `email` VARCHAR(255)  NOT NULL  DEFAULT '';
ALTER TABLE `users` ADD `name` VARCHAR(255)  NOT NULL  DEFAULT '';
ALTER TABLE `users` ADD `facebook_user_id` BIGINT  NULL  DEFAULT NULL;
ALTER TABLE `users` ADD `facebook_access_token` VARCHAR(255)  NULL  DEFAULT NULL;

Usage

Basic example:

public $components = array(
  'Auth'=> array(
    'authenticate' => array(
      'FacebookAuth.Facebook'
    )
  )
);

Slightly more interesting:

public $components = array(
  'Auth'=> array(
    'loginAction' => array(
      'controller' => 'users',
      'action' => 'login'
    ),
    'loginRedirect' => array(
      'controller' => 'users',
      'action' => 'my_account'
    ),
    'authError' => 'Did you really think you are allowed to see that?',
    'authenticate' => array(
      'FacebookAuth.Facebook' => array(
        'fields' => array(
          'username' => 'email',
    			'password' => 'password'
        )
      )
    )
  )
);

See the Cake Book for more ways to configure your CakePHP AuthComponent.

There is also an example controller included within the plugin that shows how you could implement the handler.

app/Plugin/FacebookAuth/Controller/ExampleController.php

moz-morris/cakephp-facebook-auth 适用场景与选型建议

moz-morris/cakephp-facebook-auth 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 12, 最近一次更新时间为 2013 年 01 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Authentication」 「cakephp」 「facebook」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 moz-morris/cakephp-facebook-auth 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 moz-morris/cakephp-facebook-auth 我们能提供哪些服务?
定制开发 / 二次开发

基于 moz-morris/cakephp-facebook-auth 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 12
  • 点击次数: 36
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 12
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-01-12