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

[PM-3570] Adjust refresh token lifetimes #3697

Merged
merged 6 commits into from
Feb 8, 2024
Merged

[PM-3570] Adjust refresh token lifetimes #3697

merged 6 commits into from
Feb 8, 2024

Conversation

kspearrin
Copy link
Member

@kspearrin kspearrin commented Jan 23, 2024

Type of change

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

Objective

Adjusting token lifetimes to be in line with normal use cases.

Fix grant delete implementation for EF.

Code changes

  • StaticClientStore.cs: Adjust lifetimes of refresh tokens for mobile and web.
  • GrantRepository.cs: Fix delete functions for EF. They were not working since there were never tested before.

Before you submit

  • Please check for formatting errors (dotnet format --verify-no-changes) (required)
  • If making database changes - make sure you also update Entity Framework queries and/or migrations
  • Please add unit tests where it makes sense to do so (encouraged but not required)
  • If this change requires a documentation update - notify the documentation team
  • If this change has particular deployment requirements - notify the DevOps team

@withinfocus
Copy link
Contributor

Test TokenEndpoint_GrantTypeRefreshToken_Success fails, I think due to a refresh token comparison.

Before this lands we have to confirm that all clients are re-storing the returned refresh token. We think that was the case but weren't sure 100%.

Additionally, is there any risk of hardcoded lifetimes in the clients?

@kspearrin
Copy link
Member Author

kspearrin commented Jan 24, 2024

Test TokenEndpoint_GrantTypeRefreshToken_Success fails, I think due to a refresh token comparison.

Before this lands we have to confirm that all clients are re-storing the returned refresh token. We think that was the case but weren't sure 100%.

Additionally, is there any risk of hardcoded lifetimes in the clients?

Looks like its doing some new functionality with onetime use. I see it trying to delete the old token from the grant store after it creates the new one. Cool.

System.InvalidOperationException: The entity type 'EntityQueryable<Grant>' was not found. Ensure that the entity type has been added to the model.
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.GetOrCreateEntry(Object entity)
   at Microsoft.EntityFrameworkCore.DbContext.EntryWithoutDetectChanges[TEntity](TEntity entity)
   at Microsoft.EntityFrameworkCore.DbContext.Remove[TEntity](TEntity entity)
   at Bit.Infrastructure.EntityFramework.Auth.Repositories.GrantRepository.DeleteByKeyAsync(String key) in .\server\src\Infrastructure.EntityFramework\Auth\Repositories\GrantRepository.cs:line 25
   at Bit.Identity.IdentityServer.PersistedGrantStore.RemoveAsync(String key) in .\server\src\Identity\IdentityServer\PersistedGrantStore.cs:line 56
   at Duende.IdentityServer.Stores.DefaultGrantStore`1.RemoveItemByHashedKeyAsync(String key) in /_/src/IdentityServer/Stores/Default/DefaultGrantStore.cs:line 248
   at Duende.IdentityServer.Services.DefaultRefreshTokenService.UpdateRefreshTokenAsync(RefreshTokenUpdateRequest request) in /_/src/IdentityServer/Services/Default/DefaultRefreshTokenService.cs:line 250
   at Duende.IdentityServer.ResponseHandling.TokenResponseGenerator.ProcessRefreshTokenRequestAsync(TokenRequestValidationResult request) in /_/src/IdentityServer/ResponseHandling/Default/TokenResponseGenerator.cs:line 220

@bitwarden-bot
Copy link

bitwarden-bot commented Jan 24, 2024

Logo
Checkmarx One – Scan Summary & Detailsdade1086-95fb-4893-a7e0-0660251296c8

No New Or Fixed Issues Found

Copy link

codecov bot commented Jan 24, 2024

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (9ecc479) 39.32% compared to head (b6aa272) 38.82%.

❗ Current head b6aa272 differs from pull request most recent head 28ca080. Consider uploading reports for the commit 28ca080 to get more accurate results

Files Patch % Lines
...tityFramework/Auth/Repositories/GrantRepository.cs 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3697      +/-   ##
==========================================
- Coverage   39.32%   38.82%   -0.50%     
==========================================
  Files        1032     1034       +2     
  Lines       51056    51105      +49     
  Branches     4581     4577       -4     
==========================================
- Hits        20076    19843     -233     
- Misses      30036    30330     +294     
+ Partials      944      932      -12     

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

withinfocus
withinfocus previously approved these changes Jan 24, 2024
Copy link
Contributor

@withinfocus withinfocus left a comment

Choose a reason for hiding this comment

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

Change makes sense to me. Let's ensure client compliance before we merge anything.

We'll want to ensure this acts as expected with our Cosmos store too, and meeting performance expectations for deletes.

@withinfocus withinfocus marked this pull request as ready for review January 29, 2024 18:27
@withinfocus withinfocus requested a review from a team as a code owner January 29, 2024 18:27
@JaredSnider-Bitwarden JaredSnider-Bitwarden requested review from JaredSnider-Bitwarden and removed request for andrebispo5 January 30, 2024 17:31
@kspearrin kspearrin enabled auto-merge (squash) February 8, 2024 19:38
@kspearrin kspearrin merged commit 707347c into main Feb 8, 2024
42 of 43 checks passed
@kspearrin kspearrin deleted the tokenlifetime branch February 8, 2024 21:36
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.

4 participants