fix(cli): authenticate auth register from the logged-in environment - #579
Open
Caushi wants to merge 1 commit into
Open
fix(cli): authenticate auth register from the logged-in environment#579Caushi wants to merge 1 commit into
Caushi wants to merge 1 commit into
Conversation
`auth register` prompted for an "Employee Bearer token" whenever neither --token nor --config-env was given, so a fresh `bfabric-cli login` did not help: the user had to paste a token by hand. Resolve the environment the same way every other `auth` command does (--config-env > BFABRICPY_CONFIG_ENV > configured default) and reuse its token. Obtain that token via `Bfabric.connect()` rather than rebuilding the credential provider and token-cache lookup locally -- `connect()` already resolves the environment (including the "default" sentinel), loads the cache and raises the "log in first" errors, so ~40 lines of duplicated logic go away along with the divergent error messages. Also require an explicit --service-user / --no-service-user choice, as register-webapp already does: silently defaulting to no service user registers a client without the client_credentials grant. One behaviour is deliberately not preserved: a non-OAuth (password) environment is no longer pre-screened, so its SOAP password is sent and rejected by the server instead of failing locally. Validating that belongs in connect(), not bolted onto this command.
Caushi
force-pushed
the
fix/auth-register-uses-login
branch
from
August 10, 2026 09:50
0cbe609 to
a520cec
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #573 — base is
feature/cli-auth-ux, so this diff is just theauth registerfix. Review/merge #573 first; GitHub will retarget this tomainonce it lands.The bug
auth registerprompted for an Employee Bearer token whenever neither--tokennor--config-envwas given — so immediately after a successfulbfabric-cli loginyou still had to paste a token by hand:The changelog already promises that every
authcommand resolves the environment as--config-env>BFABRICPY_CONFIG_ENV> configured default.registerwas the one command that didn't — it treated "no--config-env" as "prompt" instead of "use the default".Changes
--token,registernow authenticates as the resolved environment, sologin→registerjust works.--tokenstill works for supplying one explicitly.connect()instead of reimplementing it. The old code rebuilt theOAuthCredentialProvider+ token-cache lookup by hand (~40 lines).Bfabric.connect()already resolves the environment (including the"default"sentinel), loads the cache, and raises the "log in first" errors —register_webappwas already using exactly this. Net −12 lines inregister.pydespite adding a flag.register-webapp:--service-user LOGINor the new--no-service-user. Silently defaulting to none registers a client without theclient_credentialsgrant.--token's "prompted if omitted", and "base_url is required when --config-env is not provided").Deliberate behaviour change
A non-OAuth (
password) environment is no longer pre-screened. PreviouslyregisterprintedEnvironment 'X' does not use OAuthlocally; nowconnect()hands back the SOAP password, it's sent as a bearer token, and the server rejects it (405). Validating that belongs inconnect()— not bolted onto one CLI command — so it's left out rather than duplicated here.test_config_env_non_oauth_sends_configured_passworddocuments the new behaviour.Open question, not addressed here
register/register-webappmay be in the wrong place. Every other top-level group is noun-shaped (api,dataset,executable,workunit), whileauthis verb-shaped — session state. These two create durable server-side objects (an OAuth client, plus a B-Fabric application entity, with--technology-id/--application-id/--descriptionfields), which is noun work. Something likebfabric-cli oauth-client registermay fit better, but that's a user-visible rename and deserves its own discussion.Testing
bfabric_scriptstests pass; 16 intest_cmd_login_register.py, incl. new coverage for default-env resolution,BFABRICPY_CONFIG_ENVprecedence, explicit--config-envwinning, and the service-user choice.OAuth2Session, so they exercise the pathconnect()actually takes. Two of them previously made live HTTP requests toexample.com; both are now mocked.ruff checkandbasedpyright(bfabric_scripts)clean (0 errors).auth registerno longer prompts, and both commands now show--service-user/--no-service-user.