groton-school/oauth2-canvaslms
Composer 安装命令:
composer require groton-school/oauth2-canvaslms
包简介
Canvas LMS OAuth 2.0 support for the PHP League's OAuth 2.0 Client
README 文档
README
This package provides Canvas LMS OAuth 2.0 support for the PHP League's OAuth 2.0 Client.
Install
In your composer.json, include:
"require": { "groton-school/oauth2-canvaslms": "~1.0" }
Use
Same as the League's OAuth client, using \smtech\OAuth2\Client\Provider\CanvasLMS as the provider. Note that you can (and really should) include a purpose option parameter and you will need to include your canvasInstanceUrl.
Per the Canvas OAUth docs:
For Canvas Cloud (hosted by Instructure), you can request a client ID and secret from http://instructure.github.io/ in the Dev Key Signup section.
For open source Canvas users, you can generate a client ID and secret in the Site Admin account of your Canvas install. There will be a "Developer Keys" tab on the left navigation sidebar.
A small example:
use GrotonSchool\OAuth2\Client\Provider\CanvasLMS; session_start(); /* anti-fat-finger constant definitions */ define('CODE', 'code'); define('STATE', 'state'); define('STATE_LOCAL', 'oauth2-state'); $provider = new CanvasLMS([ 'clientId' => '160000000000127', 'clientSecret' => 'z4RUroeMI0uuRAA8h7dZy6i4QS4GkBqrWUxr9jUdgcZobpVMCEBmOGMNa2D3Ab4A', 'purpose' => 'My App Name', 'redirectUri' => 'https://' . $_SERVER['SERVER_NAME'] . '/' . $_SERVER['SCRIPT_NAME'], 'canvasInstanceUrl' => 'https://canvas.instructure.com' ]); /* if we don't already have an authorization code, let's get one! */ if (!isset($_GET[CODE])) { $authorizationUrl = $provider->getAuthorizationUrl(); $_SESSION[STATE_LOCAL] = $provider->getState(); header("Location: $authorizationUrl"); exit; /* check that the passed state matches the stored state to mitigate cross-site request forgery attacks */ } elseif (empty($_GET[STATE]) || $_GET[STATE] !== $_SESSION[STATE_LOCAL]) { unset($_SESSION[STATE_LOCAL]); exit('Invalid state'); } else { /* try to get an access token (using our existing code) */ $token = $provider->getAccessToken('authorization_code', [CODE => $_GET[CODE]]); /* do something with that token... (probably not just print to screen, but whatevs...) */ echo $token->getToken(); exit; }
groton-school/oauth2-canvaslms 适用场景与选型建议
groton-school/oauth2-canvaslms 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 837 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 groton-school/oauth2-canvaslms 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 groton-school/oauth2-canvaslms 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 837
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-19