Skip to content

Introduce hex_auth module#178

Draft
maennchen wants to merge 1 commit intohexpm:mainfrom
maennchen:jm/hex_auth
Draft

Introduce hex_auth module#178
maennchen wants to merge 1 commit intohexpm:mainfrom
maennchen:jm/hex_auth

Conversation

@maennchen
Copy link
Copy Markdown
Collaborator

@maennchen maennchen commented Apr 13, 2026

Base Module organizing Repo / API Auth Management.

This PR is WIP. I'm exploring how it could look.

Implementation PRs:

Copy link
Copy Markdown
Member

@ericmj ericmj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this fits in hex_core. It's very specific to implementing OAuth for a CLI, specifically to how Hex and rebar3 work with config resolution order and environment variables. hex_core should be more generic than that, for example you should be able to use it in web services, like hexdocs or hexdiff, and this wouldn't fit for that.

I understand we want to avoid auth logic between Hex and rebar3 if it's mostly shared, but I am not sure it fits in hex_core.

-define(EXPIRY_BUFFER_SECONDS, 300).

%% Default polling interval (seconds)
-define(DEFAULT_POLL_INTERVAL, 5).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this unused?

<<"interval">> := Interval
} = DeviceResponse,
io:format("Open ~ts in your browser and enter code: ~ts~n", [VerificationUri, UserCode]),
open_browser(VerificationUri),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want force users to open a browser? What if we are in an environment without browsers or the CLI only wants to provide the link.

%% Resolves credentials in this order:
%% <ol>
%% <li>`HEX_API_KEY' env var</li>
%% <li>Per-repo `api_key' from config (with optional OAuth exchange for hex.pm)</li>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this for rebar? In hex we don't have API keys per repository.

@maennchen
Copy link
Copy Markdown
Collaborator Author

@ericmj I'm aware that this is very much scoped towards CLIs. Is there a reason to not include a CLI only module into hex_core?

I would love to be able to reuse the auth logic that is frankly quite complicated between our clients. That way we can minimize maintenance work, are able to roll out features more quickly and also ensure better compatibility.

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.

2 participants