Skip to content

Auth: Make requirement to have username in repo URL optional? Or more doc examples #750

@glin

Description

@glin

So in the repo auth docs, the first line does say that the username is required to be in the repo URL:

To use authentication you need to include a user name in the repository URL.
https://pak.r-lib.org/dev/reference/repo-auth.html

But I had still missed this and spent some time trying to figure out why the options(repos = method wasn't working for an authenticated repo.

Other auth methods like curl with a .netrc don't require you to put the username in the repo URL, so I believe other users may hit this gotcha as well if quickly skimming through the docs.

So a few suggestions I can think of:

  1. Add an explicit example of setting the repos option to the docs. More users will be familiar with this method, and some tools like the RStudio IDE have repo settings where you just type in a repo URL.
options(repos = c(CRAN = "http://[email protected]:11235/"))
  1. Add hints to the error messaging if you omitted a username, and some netrc/keyring credentials happen to match the URL

  2. Make the username requirement optional. With curl and .netrc, usernames are optional, and curl appears to select the first .netrc entry from quick testing:

repo <- webfakes::new_app_process(pak:::auth_proxy_app(), port = 11235)
cat <<EOF > ~/.netrc
machine 127.0.0.1
login bad
password bad

machine 127.0.0.1
login username
password token
EOF
chmod 600 ~/.netrc

curl --netrc -v http://127.0.0.1:11235
# *   Trying 127.0.0.1:11235...
# * Connected to 127.0.0.1 (127.0.0.1) port 11235
# * Server auth using Basic with user 'bad'

And it finds the right entry if the username is present:

curl --netrc -v http://[email protected]:11235
# *   Trying 127.0.0.1:11235...
# * Connected to 127.0.0.1 (127.0.0.1) port 11235
# * Server auth using Basic with user 'username'

This would just be more convenient, especially since I doubt most users are going to have multiple logins configured for the same repo anyway. And also less user configuration required when converting an unauthenticated repo to authenticated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions