cli: support refresh token in tunnel user login (#212106)

This commit is contained in:
Connor Peet
2024-05-06 09:47:37 -07:00
committed by GitHub
parent 80e0aa45e0
commit e3d04f279f
3 changed files with 21 additions and 7 deletions

View File

@@ -480,6 +480,7 @@ impl Auth {
&self,
provider: Option<AuthProvider>,
access_token: Option<String>,
refresh_token: Option<String>,
) -> Result<StoredCredential, AnyError> {
let provider = match provider {
Some(p) => p,
@@ -490,8 +491,12 @@ impl Auth {
Some(t) => StoredCredential {
provider,
access_token: t,
refresh_token: None,
expires_at: None,
// if a refresh token is given, assume it's valid now but refresh it
// soon in order to get the real expiry time.
expires_at: refresh_token
.as_ref()
.map(|_| Utc::now() + chrono::Duration::minutes(5)),
refresh_token,
},
None => self.do_device_code_flow_with_provider(provider).await?,
};