Skip to content

Conversation

@tedhabeck
Copy link
Contributor

@tedhabeck tedhabeck commented Nov 11, 2025

  • Adds support for agentstack-cli automatic token refresh.

Please slack me directly if you need a working PKCE configuration to test this setup.

Automatic token refresh example:

#( 11/11/25@12:02PM )( habeck@TEDs-MacBook-Pro ):~/beeai-networking/agentstack/apps/agentstack-server@issue-1483✗✗✗
   mise agentstack-cli:run -- agent list
[agentstack-cli:run] $ uv run agentstack agent list
warning: `VIRTUAL_ENV=/Users/habeck/beeai-networking/agentstack/apps/agentstack-server/.venv` does not match the project environment path `.venv` and will be ignored; use `--active` to target the active environment instead
SHORT ID  NAME                    STATE     DESCRIPTION        INTERACTION  LOCATION               MISSING ENV  LAST ERROR
3b906a27  Chat                    ready     Agent with memor…  multi-turn   agents/chat:0.4.1-rc2  <none>       <none>    
6b27a943  RAG                     missing   RAG agent that r…  multi-turn   agents/rag:0.4.1-rc2   <none>       <none>    
1af40f1e  Single-turn Form Agent  missing   Example demonstr…  multi-turn   agents/form:0.4.1-rc2  <none>       <none>    
Finished in 9.36s
#( 11/11/25@12:17PM )( habeck@TEDs-MacBook-Pro ):~/beeai-networking/agentstack/apps/agentstack-server@issue-1483✗✗✗
   

cli login example:

  mise agentstack-cli:run -- server login 
[agentstack-sdk-py:setup] sources up-to-date, skipping
[helm:build:dependencies] sources up-to-date, skipping
[agentstack-cli:setup] sources up-to-date, skipping
[helm:build] sources up-to-date, skipping
[agentstack-cli:build:copy-helm-chart] sources up-to-date, skipping
[agentstack-cli:run] $ uv run agentstack server login
warning: `VIRTUAL_ENV=/Users/habeck/beeai-networking/agentstack/apps/agentstack-server/.venv` does not match the project environment path `.venv` and will be ignored; use `--active` to target the active environment instead
? Select a server, or log in to a new one: Log in to a new server
? Enter server URL: http://agentstack-cli.localhost:8333
📝 INFO: No authentication tokens found for this server. Proceeding to log in.
? Select an identity provider: IBMiD-PKCE
📝 INFO: Opening browser for login: 
https://isg-verify1.verify.ibm.com/oauth2/authorize?client_id=14d88fab-d185-4100-bea0-581461ef4fc7&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A9001%2Fcallback&scope=openid+email+profile&code_challenge=n941S9cSZlaJWj7Iw2t5KIALMJQsG1pNl2bfH1Z22aA&code_challenge_method=S256
✅ SUCCESS: Logged in to http://agentstack-cli.localhost:8333.
Finished in 44.47s

…or (i.e.. either "uui" or "cli"). Cli can only authenticate using PKCE providers (public client), and UI uses std OIDC providers with client id and client secret.

Signed-off-by: habeck <[email protected]>
Signed-off-by: habeck <[email protected]>
Signed-off-by: habeck <[email protected]>
@tedhabeck tedhabeck marked this pull request as ready for review November 11, 2025 20:03
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Nov 11, 2025
@tedhabeck tedhabeck requested a review from jezekra1 November 11, 2025 20:03
@tedhabeck tedhabeck added the enhancement New feature or request label Nov 11, 2025
@tomkis tomkis moved this to In dev in Agent Stack Nov 12, 2025
@tomkis tomkis linked an issue Nov 12, 2025 that may be closed by this pull request
@tomkis tomkis requested review from pilartomas and removed request for jezekra1 November 12, 2025 13:06
Copy link
Contributor

@pilartomas pilartomas left a comment

Choose a reason for hiding this comment

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

Please, only focus on the changes in auth_manager. That's all what is needed.

The remaining changes should be reverted, they introduce bugs and regressions.

Copy link

@araujof araujof left a comment

Choose a reason for hiding this comment

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

Overall, this PR makes good changes to address issues with CLI auth:

  • Token refresh implementation for handling expired tokens
  • PKCE implementation for the CLI
  • Separation of authentication concerns

However, a few changes may require discussion (and could be split into separate PRs):

  • Issues related to commented-out DCR code (# registration_endpoint = oidc["registration_endpoint"])
  • Issues related to manual client input (# if not client_id: # client_id = await inquirer.text()):
  • The app field

@tedhabeck tedhabeck requested a review from pilartomas November 20, 2025 20:49
Copy link
Contributor

@pilartomas pilartomas left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +22 to +26
"client_data": [
{"server": str(p.issuer), "client_id": p.client_id, "name": p.name}
for p in self._config.auth.oidc.providers
if p.issuer is not None
],
Copy link
Contributor

@pilartomas pilartomas Nov 26, 2025

Choose a reason for hiding this comment

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

I believe this can be also cleaned up.

By the way, I noticed Client ID Metadata RFC Draft which tries to approach this problem from a different angle but also replaces DCR in a sense. It allows client_id to be an arbitrary URL, previously unknown to the authorization server. The authorization server is then responsible for grabbing the client information dynamically during the flow itself (but making no persistent client, I believe).

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 26, 2025
@tedhabeck tedhabeck merged commit 2735ca0 into main Nov 26, 2025
11 checks passed
@tedhabeck tedhabeck deleted the issue-1483 branch November 26, 2025 15:40
@github-project-automation github-project-automation bot moved this from In dev to Done in Agent Stack Nov 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

CLI does not handle expired tokens gracefully

4 participants