定制 mapkyca/known-oauth2-server 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

mapkyca/known-oauth2-server

Composer 安装命令:

composer require mapkyca/known-oauth2-server

包简介

Provides an OAuth2 authentication server for API calls

README 文档

README

** EXPERIMENTAL **

This plugin provides an OAuth2 Server for Known, allowing users to create applications and allow clients to authenticate themselves for the API and website using an OAuth2 access token.

This plugin is an experimental basic implementation of the spec, so please, kick it around and report any issues you find!

Usage

  • Install in your plugins
  • Create an application via settings
  • Use the appropriate keys in your OAuth2 client

Support

Currently the plugin supports:

  • response_type=code
  • grant_type=authorization_code
  • grant_type=refresh_token
  • grant_type=password
  • state parameter validation
  • scope support
  • OpenID Connect

Example usage

To get a code:

https://mysite.com/oauth2/authorise/?response_type=code&client_id=<your API Key>&redirect_uri=<path to your endpoint>

You will be bounced to a login + authorisation page if necessary, so follow forwards.

As per the spec, you can omit the redirect_uri, in which case the response will be a straight json encoded blob. If redirect_uri is specified you will be forwarded to the endpoint, with appropriate parameters in the GET fields.

To get a token:

https://mysite.com/oauth2/access_token/?grant_type=authorization_code&client_id=<your API Key>&redirect_uri=<path to your endpoint>

You should get back a json encoded blob with an access token, expiry and refresh token.

To refresh a token:

If your access token has expired, you can update it with the refresh token.

https://mysite.com/oauth2/access_token/?grant_type=refresh_token&refresh_token=<refresh token>

Success will spit back a new access token, refresh token and expiry. It also results in the destruction of the original token.

Accessing the token

On a successful login the token used will be saved to the current session in $_SESSION['oauth2_token'], you can use this to check scope permissions, application ID and other details.

The scope granted to a given user is also saved against the user object in an array $user->oauth2[$client_id]['scope'], which is also cross checked on login.

Why not use native signed HTTP?

Natively, Known uses a per-user api key to sign requests, so why not use this?

Of course you can still, and the OAuth2 server doesn't replace that option. In many ways the signed HTTP approach is easier to get going, however...

  1. There are many existing libraries for OAuth2 in pretty much every language.
  2. With OAuth2 you give different credentials to each application. This means that if you no longer want to allow access from application A, but still want to keep B and C, you can revoke A's tokens specifically.

OpenID Connect

If you include the scope openid, on success the server will return an OpenID Connect signed JWT in the id_token field.

This token will include basic information about the authenticated user. If you also ask for email and profile scopes as well, you'll get some extra profile information back (email, full name, picture url, username, etc).

You can verify this token against the public key for the application (available from https://yourserver.com/oauth2/CLIENTID/key)

See

mapkyca/known-oauth2-server 适用场景与选型建议

mapkyca/known-oauth2-server 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.9k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2019 年 08 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 mapkyca/known-oauth2-server 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 9.9k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2019-08-03