Skip to content

refactor: allow any token retriever in the rest client#1553

Open
jacob720 wants to merge 1 commit into
mainfrom
service_account_client
Open

refactor: allow any token retriever in the rest client#1553
jacob720 wants to merge 1 commit into
mainfrom
service_account_client

Conversation

@jacob720

Copy link
Copy Markdown

See https://confluence.diamond.ac.uk/pages/viewpage.action?pageId=398853592&spaceKey=DCT&title=04-06-2026
Currently the rest client requires a session manager to handle retrieving auth tokens. I've made it more flexible so that it now accepts anything with a get_valid_access_token method, so a UDC client can use the same rest client.

@jacob720 jacob720 requested a review from a team as a code owner June 10, 2026 13:19
Comment thread src/blueapi/service/authentication.py Dismissed
@jacob720 jacob720 changed the title Don't require a session manager in the rest client refactor: allow any token retriever in the rest client Jun 10, 2026
@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.61%. Comparing base (ab2ebc6) to head (8e1d330).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1553   +/-   ##
=======================================
  Coverage   95.61%   95.61%           
=======================================
  Files          43       43           
  Lines        3214     3215    +1     
=======================================
+ Hits         3073     3074    +1     
  Misses        141      141           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DominicOram DominicOram left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, I think we want SessionManager to explicitly implement TokenRetriever though, right?

I also think we should add the UDCTokenRetriever (from https://github.com/DiamondLightSource/daq-queuing-service/pull/40/changes) into BlueAPI proper, it seems like a reasonable thing to have in here. Though maybe @tpoliaw disagrees?

@tpoliaw tpoliaw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks - this makes things simpler and should help when we come to refactor the login stuff in #1381.

Possibly a bit picky but can the protocol be called TokenSource or TokenProvider or similar. It's not really retrieving it if it's generating a new one and blueapi shouldn't care where it comes from.

I think we want SessionManager to explicitly implement TokenRetriever though, right?

It can do but I don't think it needs to.

I also think we should add the UDCTokenRetriever into BlueAPI proper

I'm not against the UDC ServiceAccount provider being in blueapi core but it doesn't need to be in this PR.


class JWTAuth(AuthBase):
def __init__(self, session_manager: SessionManager | None):
def __init__(self, session_manager: TokenRetriever | None):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
def __init__(self, session_manager: TokenRetriever | None):
def __init__(self, token_source: TokenRetriever | None):

class BlueapiRestClient:
_config: RestConfig
_session_manager: SessionManager | None
_token_retreiver: TokenRetriever | None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
_token_retreiver: TokenRetriever | None
_token_retriever: TokenRetriever | None

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.

3 participants