我在Git
中有一个私有的Bitbucket.org
存储库。它由Laravel
项目组成,可以用作composer
package
。我不想发布它,我只想通过将其包含在Laravel
中来将其用于我的其他composer.json
项目。我搜索了很多关于stackoverflow的教程和问题/答案,但我仍然无法做到这一点。以下是我的composer.json
文件中应该相关的部分:
"require": {
"php": ">=5.6.4",
"myprovider/mypackage": "*",
"laravel/framework": "5.4.*",
"laravel/tinker": "~1.0"
},
"repositories": {
"myrepository": {
"type": "vcs",
"url": "https://bitbucket.org/me/myrepository/"
}
},
我尝试composer require myprovider/mypackage:*
,但后来收到错误Could not fetch https://api.bitbucket.org/2.0/repositories/me/myrepository?fields=-project%2C-owner, please create a bitbucket OAuth token to access private repos
。由于我之前实际创建了OAuth令牌,因此我粘贴了所需的Consumer Key
和Consumer Secret
,但之后我得到了这个:
Invalid OAuth consumer provided.
This can have two reasons:
1. You are authenticating with a bitbucket username/password combination
2. You are using an OAuth consumer, but didn't configure a (dummy) callback url
Installation failed, reverting ./composer.json to its original content.
[Composer\Downloader\TransportException]
The "?pagelen=100&fields=values.name%2Cvalues.target.hash%2Cnext&sort=-target.date"
file could not be downloaded: failed to open stream: Resource temporarily unavailable
我是Bitbucket
的新手,我怎么知道我是否正确配置了所有内容?
一步一步的配置会非常棒,我在网上找到的所有内容都不适合我的情况。
答案 0 :(得分:2)
以下答案是我按照this blog post的说明并看到其有效后的个人笔记。
非常感谢gizmola的博客文章和gview的评论。
比方说,对于您的项目my-name/my-project
,您想要将托管在myprovider/my-private-package
的私有程序包托管在bitbucket上。
bitbucket settings
> access management
> oauth
添加oauth使用者
http://example.com
permissions
> repositories
> read
从composer oauth consumer / user for private repos
打开/创建~/.composer/auth.json
,并确保它具有替换xxxxx
和yyyyy
{
"bitbucket-oauth": {
"bitbucket.org": {
"consumer-key": "xxxxx",
"consumer-secret": "yyyyyy"
}
}
}
将您的包添加到composer.json
{
"name" : "my-name/my-project",
"description" : "my project",
"repositories": [
{
"type": "git",
"url": "https://bitbucket.org/myprovider/my-private-package.git"
}
],
"require": {
"myprovider/my-private-package": "*"
}
}
请记住,如果私有包的composer.json没有设置minimum-stability
(例如,设置为dev
),它将无法正常工作。
myprovider/my-private-package
的composer.json示例
{
"name": "myprovider/my-private-package",
"description": "my private package",
"keywords": ["private package", "private", "package"],
"type": "package",
"version": "1.0.0",
"minimum-stability": "dev",
"license": "MIT",
"authors": [
{
"name": "John Doe",
"email": "john.doe@example.com"
}
],
"autoload": {"psr-0": {"": "src"}},
"require-dev": {
"behat/behat": "^3.4"
}
}