71

I've generated a new Magento Connect key per the developer documentation instructions. How am I supposed to use this key? i.e., if I try getting info, I see the following.

$ composer info magento/sample-data
    Authentication required (repo.magento.com):
      Username: 

If I try following the new installation instructions, I get the same thing.

$ composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento2
    Authentication required (repo.magento.com):
      Username: 

Is the key my password? If so, what's the username? If the key's a true key (i.e. no usename/password needed) where do I configure the key?

Anna Völkl
  • 17,341
  • 5
  • 60
  • 141
Alana Storm
  • 44,345
  • 35
  • 168
  • 353
  • 15
    @Flyingmana The author did read through the documentation, and the documentation made no mention that a Magento key pair corresponds to composer username/password. Perhaps that's obvious to some, but it's not obvious to all. – Alana Storm Nov 20 '15 at 18:59
  • 1
    The documentation changed shortly after the GA. Out of the gate it required the account username/password (which I'm not sure work anymore), but then they updated it. Yeah…huge oversight, but at least it's using generated tokens now. :) – davidalger Nov 20 '15 at 22:54
  • I'll leave it to OP to close the question. Docs were updated after the fact. – benmarks Nov 21 '15 at 03:36
  • 9
    @Flyingmana seriously if we are going to close every question because somebody did not read the documentation.. then what is a purpose of stackexchange – Pawel Dubiel Nov 21 '15 at 21:17
  • I noticed at day 1 of magento2 released but not asked due to this reason that i was not sure about the key. @AlanStorm you are correct thank you for make it more clear. – Bhupendra Jadeja Nov 23 '15 at 11:55
  • 2
    What's the deal anyway with this login? Do they want to collect user accounts? I don't get it. – tester Dec 08 '15 at 07:02

8 Answers8

95

Magento comes with a sample file in your root as auth.json.sample you need to copy it to auth.json

It contains 2 key sets: 1 for Github and 1 for the Magento Repo

enter image description here

Enter the following data to your auth.json file to login. Please use the Public Key and the Private Key

{
    "http-basic": {
        "repo.magento.com": {
            "username":"<your public key>",
            "password":"<your private key>"
        }
    }
}

enter image description here

nb. the auth file can also be found in your user root directory and hence be used elsewhere ~/.composer/auth.json

snh_nl
  • 5,442
  • 13
  • 69
  • 133
Maddy
  • 1,566
  • 10
  • 14
  • 18
    Or enter your public key as the username and private key as the password at the prompts. – Alana Storm Nov 20 '15 at 18:38
  • 3
    the file is in ~/.composer/auth.json and in magento root – Claudiu Creanga Jan 29 '16 at 16:02
  • You must generate keys from Magento Marketplace see http://devdocs.magento.com/guides/v2.0/install-gde/prereq/connect-auth.html – himansu Dec 08 '16 at 17:40
  • 2
    why is username called public key or vice versa? The prompt should ask for public key etc! Why create the confusion with different labels? – Jon Dec 19 '16 at 12:26
  • 1
    Whenever I try to generate a new key on the site and enter in a name, the modal goes away and nothing happens. – Metropolis Nov 30 '17 at 21:14
  • Where i need to save auth.json file? – Gem May 02 '18 at 09:36
  • The position of auth.json except ~/.composer/ and magento_root_folder/, sometime it is in ~/.config/composer/(in Ubuntu 18.04). Edit the file, you could update the user of repo. – Key Shang Jul 11 '19 at 08:21
  • Once you have a Magento account and are signed in. Here is the current link for your access keys: https://marketplace.magento.com/customer/accessKeys/ – Mike Dubs Jan 24 '20 at 20:14
  • Note that the composer' configuration path has changed. Check [home] variable with command composer config --list – Begoodpy Jul 14 '21 at 07:04
36

Previous example is correct. In addition... it's also possible by composer's config command.

composer.phar global config http-basic.repo.magento.com <public_key> <private_key>

cmuench
  • 914
  • 6
  • 9
16

Login in magento using your credentials. Then follow the navigation

1.My Account

2.Marketplace

3.My Access Key

4.Magento2

Public Key: xxxxx

Private Key:xxxxx

Public Key used as user name and Private Key used as password.

Kishor Hase
  • 908
  • 11
  • 22
14

Previous examples are correct. In addition it is also possible by composer's config command.

Inside the Magento project directory execute the following Composer command:

$ composer config http-basic.repo.magento.com <public_key> <private_key>

Just replace the placeholders with the actual values (public_key will become the username and private_key the password in HTTP authentication with repo.magento.com).

The auth settings can be tested by using fetching latest version with a faked update:

$ composer update --dry-run

This will give an error message like:

Invalid credentials for 'https://repo.magento.com/packages.json', aborting.

if something is wrong with the credentials.

I can strongly suggest to manage credentials inside the project folder as my answer suggests. I also would not edit the auth.json by hand but just with the composer command as it is less error-prone.

hakre
  • 2,831
  • 4
  • 27
  • 50
  • Where i can i add this : composer.phar config http-basic.repo.magento.com <public_key> <private_key> – Gem May 02 '18 at 09:30
  • @Rathinam You don't add it, you execute it. the command is "composer", see composer documentation on how to use that utility for all the details: https://getcomposer.org – hakre May 02 '18 at 14:14
4

To Find Authentication username & password . Just follow below steps

Authentication required (repo.magento.com):
      Username: 
  1. open https://marketplace.magento.com/customer/account/ & Login
  2. Click on 'My Profile'
  3. click 'Marketplace' Then Click 'My Access' link
  4. On My Access Keys page, click on 'Magento 2' tab
  5. click on 'Create A New Access Key' button, you will get two keys Public and Private: Public Key is your username; Private Key is your password
  6. Copy key
Barry
  • 587
  • 1
  • 5
  • 22
Shorabh
  • 1,508
  • 12
  • 18
3

All answers are good just to compile possible scenarios on a single place.

Magento announced a new way to communicate to marketplace via compsoer, when you run composer install in the root directory of Magento it will prompt for username and password, remember this is not the Magento username and password it is Public and Private key of Magento Marketplace.

Login to Magento Marketplace.

Go to My Account.

Under My Products click Access Keys.

Select ver of Magento (1 or 2).

Click Create A New Access Key, in popup box name your key.

Clicking on Ok will generate pair of keys, Public and Private.

Now in Magento root or open ~/.composer/auth.json and put following lines

{
    "http-basic": {
        "repo.magento.com": {
            "username":"<your public key>",
            "password":"<your private key>"
        }
    }
}

You are good to go. Remember auth.json file contains standard json if you see any error just make sure that your auth file contains valid json, you can validate your json on JsonLint

If you don't want to add this information in above mentioned file (although it is handy, you don't need to open Marketplace dashboard repeatedly), then on run time just enter your Public key as username and Private key as your password, if you didn't add pair of keys in auth.json in previous step, don't worry Magento will ask you here whether to store this information or not, the choice is yours! :)

Adnan
  • 843
  • 8
  • 18
2

If you are trying from the command line interface :

Authentication required (repo.magento.com):
Username: "Your public key"
Password: "Your private key"

Remember here Username means "public key" and password means "private key"
Keep developing...

gurcharan
  • 41
  • 1
1

If this code will give error like auth.json does not contain valid JSON Parse error on line 1:

"http-basic": {
    "repo.magento.com": {
       "username":"<your public key>",
       "password":"<your private key>"
    }
}

Than it will be like below:

{
    "http-basic": {
       "repo.magento.com": {
          "username":"<your public key>",
          "password":"<your private key>"
        }
    }
}

Here You should Wrap your auth.json File with extra {}

Nirav Joshi
  • 69
  • 16