Skip to content

Commit eff496e

Browse files
authored
fix: Refresh bearer token when expired (#1823)
1 parent 0a43fd2 commit eff496e

File tree

4 files changed

+6
-19
lines changed

4 files changed

+6
-19
lines changed

crates/chat-cli/src/api_client/clients/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl Client {
5555
.http_client(crate::aws_common::http_client::client())
5656
.interceptor(OptOutInterceptor::new(database))
5757
.interceptor(UserAgentOverrideInterceptor::new())
58-
.bearer_token_resolver(BearerResolver::new(database).await?)
58+
.bearer_token_resolver(BearerResolver)
5959
.app_name(app_name())
6060
.endpoint_url(endpoint.url())
6161
.build();

crates/chat-cli/src/api_client/clients/streaming_client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl StreamingClient {
9090
.http_client(crate::aws_common::http_client::client())
9191
.interceptor(OptOutInterceptor::new(database))
9292
.interceptor(UserAgentOverrideInterceptor::new())
93-
.bearer_token_resolver(BearerResolver::new(database).await?)
93+
.bearer_token_resolver(BearerResolver)
9494
.app_name(app_name())
9595
.endpoint_url(endpoint.url())
9696
.stalled_stream_protection(stalled_stream_protection_config())

crates/chat-cli/src/auth/builder_id.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -518,17 +518,7 @@ pub async fn logout(database: &mut Database) -> Result<(), AuthError> {
518518
}
519519

520520
#[derive(Debug, Clone)]
521-
pub struct BearerResolver {
522-
token: Option<BuilderIdToken>,
523-
}
524-
525-
impl BearerResolver {
526-
pub async fn new(database: &mut Database) -> Result<Self, AuthError> {
527-
Ok(Self {
528-
token: BuilderIdToken::load(database).await?,
529-
})
530-
}
531-
}
521+
pub struct BearerResolver;
532522

533523
impl ResolveIdentity for BearerResolver {
534524
fn resolve_identity<'a>(
@@ -537,7 +527,8 @@ impl ResolveIdentity for BearerResolver {
537527
_config_bag: &'a ConfigBag,
538528
) -> IdentityFuture<'a> {
539529
IdentityFuture::new_boxed(Box::pin(async {
540-
match &self.token {
530+
let database = Database::new().await?;
531+
match BuilderIdToken::load(&database).await? {
541532
Some(token) => Ok(Identity::new(
542533
Token::new(token.access_token.0.clone(), Some(token.expires_at.into())),
543534
Some(token.expires_at.into()),

crates/chat-cli/src/cli/chat/mcp.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,7 @@ mod tests {
344344

345345
// profile
346346
let p = resolve_scope_profile(&ctx, Some(Scope::Profile), Some(&"qa")).unwrap();
347-
assert_eq!(
348-
p,
349-
profile_mcp_config_path(&ctx, &"qa").unwrap(),
350-
"profile path mismatch"
351-
);
347+
assert_eq!(p, profile_mcp_config_path(&ctx, "qa").unwrap(), "profile path mismatch");
352348
}
353349

354350
#[ignore = "TODO: fix in CI"]

0 commit comments

Comments
 (0)