aysnc/composer-env-auth
Composer 安装命令:
composer require aysnc/composer-env-auth
包简介
Composer plugin that reads authentication credentials from environment variables and .env files
README 文档
README
Streamline your Composer authentication with environment variables
Are you managing separate .env files alongside auth.json files for your Composer authentication? This plugin eliminates that redundancy by bringing industry-standard environment variable support directly to Composer's authentication system.
While we await native environment variable support in Composer core, this plugin bridges the gap by allowing you to store all your authentication credentials securely in environment variables — just like every other modern development tool.
Features
- 🔐 Unified Authentication: Store all credentials in environment variables
- 🚀 Zero Configuration: Works automatically once installed
- 🎯 Multiple Auth Types: Supports GitHub OAuth, GitLab tokens, and HTTP Basic auth
- 📁 Project-Aware: Automatically finds your project root and
.envfile - ⚡ Lightweight: Minimal overhead, maximum convenience
Installation
Install the plugin as a development dependency in your project. Do this before installing any plugins:
composer require --dev aysnc/composer-env-auth
Quick Start
- Add authentication configuration to your
composer.json:
{
"repositories": [
{
"type": "composer",
"url": "https://connect.advancedcustomfields.com",
"options": {
"aysnc/env-auth": {
"username": "ACF_USERNAME",
"password": "ACF_PASSWORD"
}
}
}
]
}
- Set your credentials in your
.envfile:
ACF_USERNAME=your_acf_license_key ACF_PASSWORD=your_acf_license_key
- Run Composer commands as usual:
composer require wpengine/advanced-custom-fields-pro
The plugin automatically applies your environment-based authentication!
Configuration Examples
HTTP Basic Authentication (Generic)
{
"repositories": [
{
"type": "composer",
"url": "https://repo.example.com",
"options": {
"aysnc/env-auth": {
"username": "API_USERNAME",
"password": "API_PASSWORD"
}
}
}
]
}
# .env
API_USERNAME=your_username
API_PASSWORD=your_password_or_token
GitHub Personal Access Token
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/your-org/private-repo.git",
"options": {
"aysnc/env-auth": "GITHUB_TOKEN"
}
}
]
}
# .env
GITHUB_TOKEN=ghp_your_token_here
GitLab Private Token
{
"repositories": [
{
"type": "vcs",
"url": "https://gitlab.com/your-org/private-repo.git",
"options": {
"aysnc/env-auth": "GITLAB_TOKEN"
}
}
],
"require": {
"your-org/private-package": "^1.0",
"another-org/repo": "dev-main"
}
}
# .env
GITLAB_TOKEN=glpat-your_token_here
Multiple Repositories
{
"repositories": [
{
"type": "composer",
"url": "https://connect.advancedcustomfields.com",
"options": {
"aysnc/env-auth": {
"username": "ACF_USERNAME",
"password": "ACF_PASSWORD"
}
}
},
{
"type": "composer",
"url": "https://repo.custom.com",
"options": {
"aysnc/env-auth": {
"username": "CUSTOM_USER",
"password": "CUSTOM_TOKEN"
}
}
},
{
"type": "vcs",
"url": "https://github.com/org-one/repo.git",
"options": {
"aysnc/env-auth": "GITHUB_TOKEN"
}
},
{
"type": "vcs",
"url": "https://gitlab.com/org-two/repo.git",
"options": {
"aysnc/env-auth": "GITLAB_TOKEN"
}
}
]
}
How It Works
- Plugin Activation: Automatically activated when Composer initializes
- Configuration Discovery: Scans
composer.jsonfor repositories withaysnc/env-authoptions - Environment Resolution: Resolves variables from system environment and
.envfiles - Authentication Configuration: Dynamically configures Composer's authentication system
- Seamless Integration: Standard Composer commands operate with authenticated access
CI/CD Pipeline Integration
The plugin seamlessly integrates with CI/CD environments where .env files may not be present:
# GitHub Actions example env: ACF_USERNAME: ${{ secrets.ACF_USERNAME }} ACF_PASSWORD: ${{ secrets.ACF_PASSWORD }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} # GitLab CI example variables: ACF_USERNAME: $ACF_USERNAME ACF_PASSWORD: $ACF_PASSWORD GITHUB_TOKEN: $GITHUB_TOKEN GITLAB_TOKEN: $GITLAB_TOKEN
System environment variables are automatically detected and utilized without requiring local .env files.
Environment Variable Priority
The plugin resolves environment variables in the following order of precedence:
- System environment variables (
$_ENV,$_SERVER) - highest priority - Variables from
.envfile in your project root - fallback
This hierarchy ensures that system-level configuration (such as CI/CD pipeline variables) takes precedence over local development settings, while maintaining backwards compatibility with existing .env file workflows.
Supported Authentication Types
| Service | Configuration | Environment Variable Format |
|---|---|---|
| Generic | {"username": "USER_VAR", "password": "PASS_VAR"} |
Username/Password or Token |
| GitHub | "GITHUB_TOKEN" |
Personal Access Token |
| GitLab | "GITLAB_TOKEN" |
Private Token |
Why This Plugin?
The Challenge: Traditional Composer authentication requires maintaining separate auth.json files alongside application .env configurations, resulting in:
- Fragmented credential management workflows
- Increased risk of credential exposure in version control
- Inconsistent authentication patterns across development tools
- Complex CI/CD configuration requirements
Our Solution: This plugin aligns Composer with industry-standard practices by implementing comprehensive environment variable support for authentication workflows.
Looking Forward: While we anticipate eventual native environment variable support in Composer core, this plugin provides an immediate, production-ready solution that standardizes authentication practices across modern development workflows.
aysnc/composer-env-auth 适用场景与选型建议
aysnc/composer-env-auth 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Authentication」 「plugin」 「composer」 「environment」 「env」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 aysnc/composer-env-auth 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 aysnc/composer-env-auth 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 aysnc/composer-env-auth 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
CakePHP 4.x AdminLTE Theme.
Automatically logs-in users if they are already authenticated by a remote source. (e.g. environment variable REMOTE_USER)
GraphQL authentication for your headless Craft CMS applications.
Laravel middleware to restrict a site or specific routes using HTTP basic authentication
This composer plugin enables installation of GravityForms WordPress plugin and its addons.
Email Toolkit Plugin for CakePHP
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-13