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

[SM-1189] Fix renew for service account access token logins #702

Merged
merged 4 commits into from
Apr 22, 2024

Conversation

Thomas-Avery
Copy link
Contributor

@Thomas-Avery Thomas-Avery commented Apr 9, 2024

Type of change

- [X] Bug fix
- [ ] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other

Objective

Fix renew_token to properly client.set_tokens(r.access_token, r.refresh_token, r.expires_in) when logged in via service account access token.

When the client's OAuth token expired, a call would be made to the identity server, but the OAuth token was never replaced on the client.

The response would map to nothing https://github.com/bitwarden/sdk/blob/a5692418b5836acd3662ce425258d660614bf7f3/crates/bitwarden/src/auth/renew.rs#L87-L90

Then silently error here
https://github.com/bitwarden/sdk/blob/4a339a911e6db1583465f69b4c9ff981104ea0ef/crates/bitwarden/src/client/client.rs#L170-L175

This occurs when a client successfully client.auth().login_access_token via state, but then shortly after the OAuth token would expire.
Subsequent calls would produce HTTP 401.

An easier way to produce the error is to log in without state thread::sleep(Duration::from_secs(4000)); then attempt to make any client call.

Code changes

  • crates/bitwarden/src/auth/renew.rs:
    Match to the IdentityTokenResponse:Payload returned by the access token request to the identity server.

Before you submit

  • Please add unit tests where it makes sense to do so

Copy link
Contributor

github-actions bot commented Apr 9, 2024

Logo
Checkmarx One – Scan Summary & Detailsb7cc54b3-d6f7-45a1-870d-b99d68863563

No New Or Fixed Issues Found

Copy link

codecov bot commented Apr 9, 2024

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 60.71%. Comparing base (a863e89) to head (e49c976).

Files Patch % Lines
crates/bitwarden/src/auth/renew.rs 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #702      +/-   ##
==========================================
- Coverage   60.72%   60.71%   -0.01%     
==========================================
  Files         173      173              
  Lines       10637    10638       +1     
==========================================
  Hits         6459     6459              
- Misses       4178     4179       +1     

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

@Thomas-Avery Thomas-Avery self-assigned this Apr 9, 2024
@Thomas-Avery Thomas-Avery marked this pull request as ready for review April 9, 2024 23:15
Copy link
Contributor

@cd-bitwarden cd-bitwarden left a comment

Choose a reason for hiding this comment

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

LGTM :)

@Thomas-Avery Thomas-Avery merged commit 435cecd into main Apr 22, 2024
76 checks passed
@Thomas-Avery Thomas-Avery deleted the sm/sm-1189 branch April 22, 2024 14:54
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