Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add token support #16

Merged
merged 12 commits into from
Oct 21, 2023
Merged

Add token support #16

merged 12 commits into from
Oct 21, 2023

Conversation

travishathaway
Copy link
Collaborator

@travishathaway travishathaway commented Oct 6, 2023

Fixes: #15

Important changes

  • Adds support for token based authentication via the conda_auth.handlers.token module
  • Removes authentication verification; I think this needs to be handled in a separate feature because the current solution I have just doesn't work well for token authentication; this will be handled with Add support to verify authentication credentials #17
  • Removes the OAuth2 code; this was just an experimental thing I did when first developing the plugin. Will handle support separately in this issue Add support for OAuth2 authentication #7

Description

This adds support for token based authentication. It aims to support existing token based authentication with anaconda.org as well as adding support for other "bearer" compatible token authentication platforms (e.g. prefix.dev).

To add a token, run the following command:

# With an anaconda.org channel
conda auth login <channel> --token <token>
# With a prefix.dev channel
conda auth login https://repo.prefix.dev/<channel> --token <channel>

This will trigger a new entry to be written to your .condarc file. It looks like this:

channel_settings:
- channel: <channel>
  username: token
  auth: token
- channel: https://repo.prefix.dev/<channel>
  username: token
  auth: token

On subsequent runs with conda, that configuration will be read and the correct token will be found via the keyring library.

To remove the token from the keyring, run:

conda auth logout <channel>

@travishathaway travishathaway marked this pull request as draft October 6, 2023 13:19
@wolfv
Copy link

wolfv commented Oct 6, 2023

This is great!

@travishathaway travishathaway marked this pull request as ready for review October 8, 2023 08:26
@codecov
Copy link

codecov bot commented Oct 9, 2023

Codecov Report

Merging #16 (44a3aef) into main (cc2e03c) will increase coverage by 7.85%.
The diff coverage is 97.36%.

@@            Coverage Diff             @@
##             main      #16      +/-   ##
==========================================
+ Coverage   90.62%   98.47%   +7.85%     
==========================================
  Files          10       11       +1     
  Lines         320      328       +8     
==========================================
+ Hits          290      323      +33     
+ Misses         30        5      -25     
Flag Coverage Δ
3.11 98.47% <97.36%> (+7.85%) ⬆️
3.8 98.47% <97.36%> (+7.85%) ⬆️
Linux 98.47% <97.36%> (+7.85%) ⬆️
Windows 98.46% <97.35%> (+7.92%) ⬆️
macOS 98.47% <97.36%> (+7.85%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
conda_auth/cli.py 98.68% <100.00%> (+0.05%) ⬆️
conda_auth/constants.py 100.00% <ø> (ø)
conda_auth/handlers/__init__.py 100.00% <100.00%> (ø)
conda_auth/handlers/basic_auth.py 100.00% <100.00%> (+8.95%) ⬆️
conda_auth/handlers/token.py 100.00% <100.00%> (ø)
conda_auth/hooks.py 100.00% <100.00%> (+29.41%) ⬆️
conda_auth/condarc.py 97.05% <75.00%> (-2.95%) ⬇️
conda_auth/handlers/base.py 98.03% <90.90%> (+20.42%) ⬆️
conda_auth/options.py 89.47% <89.47%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

conda_auth/cli.py Outdated Show resolved Hide resolved
tests/handlers/test_base.py Outdated Show resolved Hide resolved
conda_auth/handlers/token.py Outdated Show resolved Hide resolved
conda_auth/handlers/base.py Outdated Show resolved Hide resolved
conda_auth/handlers/token.py Outdated Show resolved Hide resolved
conda_auth/cli.py Outdated Show resolved Hide resolved
@beeankha
Copy link
Member

Would it be practical to remove the channel name + auth type from the .condarc file after a logout command is run? Not a blocker for this by any means, just curious. For example, if there's a slightly mistyped channel name that shows a "success" message with a login attempt, that channel with a typo is persistent in the config file no matter what (at least from my understanding).

Co-authored-by: Bianca Henderson <[email protected]>
@travishathaway
Copy link
Collaborator Author

@beeankha,

I thought about doing this, but conda auth isn't the only command that may be editing these settings in the future, so removing a channel completely could be removing whatever other settings are associated with it.

I think for now we should just let users edit this file themselves. A future feature request could be to remove the conda auth related settings for a channel when logging out.

@travishathaway travishathaway merged commit e6d6ade into main Oct 21, 2023
11 checks passed
travishathaway added a commit that referenced this pull request Oct 21, 2023
Suggested changes for token support (#16)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for token based authentication
4 participants