Download the PHP package tourze/wechat-official-account-oauth2-bundle without Composer
On this page you can find all versions of the php package tourze/wechat-official-account-oauth2-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tourze/wechat-official-account-oauth2-bundle
More information about tourze/wechat-official-account-oauth2-bundle
Files in tourze/wechat-official-account-oauth2-bundle
Package wechat-official-account-oauth2-bundle
Short Description 微信公众号OAuth2授权
License MIT
Informations about the package wechat-official-account-oauth2-bundle
WeChat Official Account OAuth2 Bundle
中文
A complete OAuth2 authorization solution for WeChat Official Accounts in Symfony applications.
Table of Contents
- Features
- Installation
- Usage
- API Endpoints
- Authorization Scopes
- Error Handling
- Security Recommendations
- Development and Testing
- Service Classes
- Dependencies
- License
- Contributing
Features
- 🔐 Standard OAuth2 authorization code flow
- 🎯 WeChat Official Account user authorization
- 👤 Get user basic and detailed information
- 🔄 Automatic access token refresh
- 🗃️ Token management and cleanup
- 🛡️ Secure client authentication
- 📊 EasyAdmin backend integration
- 🧪 Complete unit and integration tests
Installation
1. Install via Composer
2. Add Bundle to Kernel
3. Database Migration
4. Configure WeChat Official Account
Ensure you have configured your WeChat Official Account information in wechat-official-account-bundle.
Usage
1. Create OAuth2 Application
Parameters:
1: WeChat Official Account ID--redirect-uri: Authorization callback URL (multiple allowed)--scope: Default authorization scope
2. OAuth2 Authorization Flow
Step 1: User Authorization
Redirect users to the authorization page:
Parameters:
client_id: OAuth2 client IDredirect_uri: Authorization callback URLscope: Authorization scope (snsapi_baseorsnsapi_userinfo)state: Random string for CSRF protectionresponse_type: Fixed valuecode
Step 2: Get Access Token
Exchange authorization code for access token:
Response Example:
Step 3: Get User Information
Get user information using access token:
Step 4: Refresh Access Token
3. Token Management
Revoke Token
Token Introspection
4. Console Commands
OAuth2 Configuration Command
Configure OAuth2 settings for WeChat Official Account:
Parameters:
account-id: WeChat Official Account ID--scope: Authorization scope (optional, default: snsapi_base)--remark: Configuration remark (optional)
Examples:
Refresh Token Command
Automatically refresh expiring access tokens:
Parameters:
--expires-within: Tokens expiring within specified time range (optional, default: 2 hours)--force: Force refresh all tokens regardless of expiration (optional)
5. Scheduled Cleanup
It's recommended to set up a cron job to clean up expired tokens:
API Endpoints
| Endpoint | Method | Description |
| /oauth2/authorize | GET | User authorization page |
| /oauth2/callback | GET | WeChat authorization callback |
| /oauth2/token | POST | Get access token |
| /oauth2/refresh | POST | Refresh access token |
| /oauth2/revoke | POST | Revoke token |
| /oauth2/userinfo | GET/POST | Get user information |
| /oauth2/introspect | POST | Token introspection |
Authorization Scopes
snsapi_base: Silent authorization, only get user's openidsnsapi_userinfo: Requires user's manual consent, can get user's basic information
Error Handling
All error responses follow the OAuth2 standard format:
Common Error Codes:
invalid_request: Invalid request parametersinvalid_client: Client authentication failedinvalid_grant: Invalid or expired authorization codeinvalid_token: Invalid access tokenunsupported_grant_type: Unsupported grant type
Security Recommendations
- 🔒 Keep Client Secret secure and avoid leakage
- 🌐 Only use OAuth2 features in HTTPS environment
- ✅ Strictly validate redirect_uri parameter
- ⏰ Set reasonable token expiration times
- 🧹 Regularly clean up expired authorization codes and tokens
Development and Testing
Running Tests
Note: Some integration tests may experience conflicts due to Symfony configuration class loading in the same PHP process. This is a known issue tracked in Issue #774. Unit tests (Entity, Exception tests) run without issues.
Code Quality Checks
Service Classes
OAuth2AuthorizationService
OAuth2UserInfoService
WechatOAuth2Service
Dependencies
This bundle depends on the following components:
wechat-official-account-bundle: WeChat Official Account basic functionalityhttp-client-bundle: HTTP client wrappersymfony-routing-auto-loader-bundle: Automatic route loadingdoctrine-snowflake-bundle: Snowflake ID generationdoctrine-indexed-bundle: Database indexing supportdoctrine-timestamp-bundle: Automatic timestamp handlingdoctrine-track-bundle: Entity tracking featuresdoctrine-user-bundle: User management features
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
📝 Note: Before using in production, ensure all features are thoroughly tested and configured according to WeChat's official documentation.
All versions of wechat-official-account-oauth2-bundle with dependencies
doctrine/collections Version ^2.3
doctrine/data-fixtures Version ^2.0
doctrine/dbal Version ^4.0
doctrine/doctrine-bundle Version ^2.13
doctrine/doctrine-fixtures-bundle Version ^4.0
doctrine/orm Version ^3.0
doctrine/persistence Version ^4.1
easycorp/easyadmin-bundle Version ^4
knplabs/knp-menu Version ^3.7
monolog/monolog Version ^3.1
psr/log Version ^3|^2|^1
symfony/config Version ^7.3
symfony/console Version ^7.3
symfony/dependency-injection Version ^7.3
symfony/doctrine-bridge Version ^7.3
symfony/event-dispatcher Version ^7.3
symfony/framework-bundle Version ^7.3
symfony/http-foundation Version ^7.3
symfony/http-kernel Version ^7.3
symfony/property-access Version ^7.3
symfony/routing Version ^7.3
symfony/security-bundle Version ^7.3
symfony/twig-bundle Version ^7.3
symfony/yaml Version ^7.3
tourze/bundle-dependency Version 1.*
tourze/doctrine-indexed-bundle Version 1.0.*
tourze/doctrine-resolve-target-entity-bundle Version 1.*
tourze/doctrine-snowflake-bundle Version 1.1.*
tourze/doctrine-timestamp-bundle Version 1.1.*
tourze/doctrine-track-bundle Version 1.1.*
tourze/doctrine-user-bundle Version 1.0.*
tourze/easy-admin-menu-bundle Version 1.0.*
tourze/http-client-bundle Version 1.1.*
tourze/symfony-dependency-service-loader Version 1.0.*
tourze/symfony-routing-auto-loader-bundle Version 1.0.*
tourze/wechat-official-account-bundle Version 0.1.*
tourze/wechat-official-account-contracts Version 0.0.*