承接 ikkez/f3-opauth 相关项目开发

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

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

ikkez/f3-opauth

Composer 安装命令:

composer require ikkez/f3-opauth

包简介

Opauth Plugin for PHP Fat-Free Framework

README 文档

README

This is a plugin for easy integration of Opauth for PHP Fat-Free Framework.

Installation

  • A: use composer composer require ikkez/f3-opauth
  • or B: put the opauth folder somewhere into your libs or autoloaded directory, and adjust the autoload path:
// adjust the autoloader
$f3->set('AUTOLOAD','lib/opauth/');

Configuration

  1. You need to configure each strategy you want to use on your service. You can find instructions how to do that in each strategy folder's readme file. Basically you only need to create some OAuth consumer apps on the strategy's provider and add the key/secret credentials to the config file. Google,Facebook,Twitter,and Github are already included here, so you can skip the Install part in their readme files. If you need more OAuth providers, check the the list of strategies.
  2. This plugin comes with its own configuration file. It's used to provide all strategy configuration to Opauth, as well as some F3 routing settings. You should at least change the security_salt and your favorite strategy keys and secrets.
  3. Integrate the authorization into your existing login procedure.

Basic Usage

// in your index.php
$f3 = \Base::instance();
// load opauth config (allow token resolve)
$f3->config('lib/opauth/opauth.ini', TRUE);

// init with config
$opauth = OpauthBridge::instance($f3->opauth);

// define login handler
$opauth->onSuccess(function($data){
	header('Content-Type: text');
	echo 'User successfully authenticated.'."\n";
	print_r($data['info']);
});

// define error handler
$opauth->onAbort(function($data){
	header('Content-Type: text');
	echo 'Auth request was canceled.'."\n";
	print_r($data);
});

$f3->run();

The event handlers can also be callable string:

$opauth->onSuccess('\Controller\User->socialLogin');

To login, call a strategy, i.e.http://domain.com/auth/facebook.

Application flow

  1. Alright, you place a social login button near your regular login form, that send the user to the login strategy, i.e. http://domain.com/auth/facebook.
  2. When a user authenticated to a provider, the user is send back to a callback-route. The callback checks if the request and auth was valid. Then, when the authorization was successful, the onSuccess handler is called and provides you some data from the given strategy.
  3. You can use this data to extract a username, access-token, email or what ever suits best for that strategy. Each strategy provides different data, so depending on your application needs, you perhaps should consider to add some fallback mechanisms into your application (i.e. it can happen that you wont get an email from twitter or facebook). You can use this data to find a match in your user database. Depending on the result you can start your login or registration controller.
  4. On registration, you might want to save that unique-something from the strategy-auth-data to the user table (email, or $f3->hash on multiple fields like username,token,id) - this way you know who has activated a social auth provider and get the chance to load the user based on this.
  5. After registration and on login, you probably save an active user session in your controller to memorize your logged in user.
  6. When the session is expired or the user need to login again from another device, send him to the auth strategy route again (auth/facebook - instant redirect after successful activation on most providers), and now you can find him in your user table with activated social auth and login him in directly.

This is of course just one idea of implementation. Some providers also return tokens for further communication with their 3rd party API (i.e. to fetch more profile data or renew tokens), but that's something this plugin is not going to handle. Have a look at the strategy docs for more information.

Demo

License

GPLv3

ikkez/f3-opauth 适用场景与选型建议

ikkez/f3-opauth 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.04k 次下载、GitHub Stars 达 32, 最近一次更新时间为 2015 年 08 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 ikkez/f3-opauth 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 2.04k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 32
  • 点击次数: 26
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 32
  • Watchers: 6
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2015-08-21