rleekg/craft-cognito-auth
Composer 安装命令:
composer require rleekg/craft-cognito-auth
包简介
Enable authentication to Craft using AWS Cognito
README 文档
README
Craft Cognito Auth plugin
Enable authentication to Craft using AWS Cognito.
Overview
This plugin enables requests to Craft to be securely authenticated in the presence of a Cognito JWT that can be successfully verified as matching a JWKS signature.
JSON Web Tokens are an open, industry standard RFC 7519 method for representing claims securely between two parties.
-- jwt.io
Features
- Create and verify users with Cognito.
- Authenticate requests to Craft from mobile apps and websites via JWT.
- SAML Authentication.
Requirements
This plugin requires Craft CMS 3.7 or later.
Installation
-
Follow the Craft CMS documentation to set up your local Craft instance.
-
Load the plugin with Composer:
nitro composer require levinriegner/craft-cognito-auth -
On your browser, open your local Craft Control Panel, navigate to Settings → Plugins, and click the "Install" button for Craft Cognito Auth.
Configuration
Navigate to the settings page of the plugin and enter required settings to activate the plugin:
| Setting | Description |
|---|---|
| General configuration | |
Auto create user |
Optional. Enable to auto-create a public user when provided a verifiable JWT. |
| Cognito configuration | |
Enable JWT token handling |
Optional. Enable to automatically parse incoming JWT tokens and try to login the user |
AWS Cognito region |
Mandatory. AWS cognito region. |
AWS Cognito app client id |
Mandatory. AWS Cognito app client id (under App integration -> app client settings). |
AWS Cognito user pool id |
Mandatory. AWS Cognito user pool id (under General settings). |
JSON Web Key Set URL |
Mandatory. JSON Web Key Set URL (JWKS), used for verifying incoming Cognito JWTs. |
| SAML configuration | |
SAML token handling |
Optional. Enable to automatically parse incoming SAML tokens and try to login the user |
SAML Certificate |
Mandatory. Your SAML Certificate, used for verifying incoming SAML messages |
SAML Login URL |
Mandatory. The SAML IdP login URL |
This plugin asumes AWS Cognito is configured so that users sign up and sign in with email instead of username and that the App client being used has the sign-in API for server-based authentication (ADMIN_NO_SRP_AUTH) enabled as stated in the AWS docs
Usage
The plugin will attempt to verify any incoming requests with a JWT present in the Authentication header with a Bearer prefix, or with the simpler X-Access-Token header value. An example:
# With Authorization: Bearer curl --header "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.XbPfbIHMI6arZ3Y922BhjWgQzWXcXNrz0ogtVhfEd2o" MYCRAFTSITE.com # With X-Access-Token curl --header "X-Access-Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.XbPfbIHMI6arZ3Y922BhjWgQzWXcXNrz0ogtVhfEd2o" MYCRAFTSITE.com
The plugin will attempt to verify the token using the lcobucci/jwt package for PHP. The package adheres to the IANA specifications for JWTs.
If a provided token can be verified AND can be matched to a user account with a username matching the provided sub key, the user will be authenticated and the request allowed to continue.
If the token is verifiable but a matching user account does NOT exist, but the Auto create user setting is enabled AND public registration is enabled in the Craft settings, a new user account will be created on-the-fly and the new user then logged in.
This plugin provides example templates for you to use as a reference when building out your authentication solution. The example templates can by found in the templates folder.
Deployment
- Update version number in
composer.json. - Add a new entry in
CHANGELOG.mddocumenting the changes made. - Push a new tag matching the new version number with the following format:
vX.Y.Z.
Contributing
Contributions are most welcome! Feel free to open a new issue or pull request to make this project better.
Credits
A big thank you to:
- craft-jwt-auth - Copyright (c) 2019 Mike Pierce MIT License for the initial codebase.
- @goraxan for the ongoing development.
License
This repo is covered under the MIT License.
rleekg/craft-cognito-auth 适用场景与选型建议
rleekg/craft-cognito-auth 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cms」 「Craft」 「craftcms」 「Cognito」 「craft-plugin」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rleekg/craft-cognito-auth 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rleekg/craft-cognito-auth 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rleekg/craft-cognito-auth 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Expand, collapse, change the status of, or delete multiple blocks in a Matrix field simultaneously.
GraphQL authentication for your headless Craft CMS applications.
Set Links with a specific language parameter
Supercharged text field validation.
Integrate with Snipcart.
Restrict user registration by domain in Craft CMS, allows you to limit who can register for your site based on their email address.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-08
