Commit 69765a6 1 parent 8a24ab8 commit 69765a6 Copy full SHA for 69765a6
File tree 3 files changed +28
-10
lines changed
3 files changed +28
-10
lines changed Original file line number Diff line number Diff line change @@ -312,7 +312,7 @@ pub async fn refresh_authorizations(
312
312
( Some ( access) , None ) => {
313
313
// We have an access token but no refresh token. Create one.
314
314
let refresh_token = api_exec :: < RefreshToken > (
315
- client. rpc (
315
+ client. clone ( ) . with_creds ( Some ( access . to_owned ( ) ) ) . rpc (
316
316
"create_refresh_token" ,
317
317
serde_json:: json!( { "multi_use" : true , "valid_for" : "90d" , "detail" : "Created by flowctl" } )
318
318
. to_string ( ) ,
Original file line number Diff line number Diff line change 1
1
mod roles;
2
2
3
3
use anyhow:: Context ;
4
+ use flow_client:: client:: refresh_authorizations;
4
5
5
6
#[ derive( Debug , clap:: Args ) ]
6
7
#[ clap( rename_all = "kebab-case" ) ]
@@ -64,7 +65,20 @@ impl Auth {
64
65
Ok ( ( ) )
65
66
}
66
67
Command :: Roles ( roles) => roles. run ( ctx) . await ,
67
- }
68
+ } ?;
69
+
70
+ // Ensure that any changes to the credentials fully propagate
71
+ // i.e if an access token is changed, we also need to make sure
72
+ // to generate and store an updated refresh token.
73
+ let ( access_token, refresh_token) = refresh_authorizations (
74
+ & ctx. client ,
75
+ ctx. config . user_access_token . to_owned ( ) ,
76
+ ctx. config . user_refresh_token . to_owned ( ) ,
77
+ )
78
+ . await ?;
79
+ ctx. config . user_access_token = Some ( access_token) ;
80
+ ctx. config . user_refresh_token = Some ( refresh_token) ;
81
+ Ok ( ( ) )
68
82
}
69
83
}
70
84
Original file line number Diff line number Diff line change @@ -136,21 +136,25 @@ impl Cli {
136
136
137
137
let anon_client: flow_client:: Client = config. build_anon_client ( ) ;
138
138
139
- let client = if let Ok ( ( access , refresh ) ) = refresh_authorizations (
139
+ let client = match refresh_authorizations (
140
140
& anon_client,
141
141
config. user_access_token . to_owned ( ) ,
142
142
config. user_refresh_token . to_owned ( ) ,
143
143
)
144
144
. await
145
145
{
146
- // Make sure to store refreshed tokens back in Config so they get written back to disk
147
- config. user_access_token = Some ( access. to_owned ( ) ) ;
148
- config. user_refresh_token = Some ( refresh. to_owned ( ) ) ;
146
+ Ok ( ( access, refresh) ) => {
147
+ // Make sure to store refreshed tokens back in Config so they get written back to disk
148
+ config. user_access_token = Some ( access. to_owned ( ) ) ;
149
+ config. user_refresh_token = Some ( refresh. to_owned ( ) ) ;
149
150
150
- anon_client. with_creds ( Some ( access) )
151
- } else {
152
- tracing:: warn!( "You are not authenticated. Run `auth login` to login to Flow." ) ;
153
- anon_client
151
+ anon_client. with_creds ( Some ( access) )
152
+ }
153
+ Err ( err) => {
154
+ tracing:: debug!( ?err, "Error refreshing credentials" ) ;
155
+ tracing:: warn!( "You are not authenticated. Run `auth login` to login to Flow." ) ;
156
+ anon_client
157
+ }
154
158
} ;
155
159
156
160
let mut context = CliContext {
You can’t perform that action at this time.
0 commit comments