@@ -75,72 +75,72 @@ impl CreatePublic {
7575 pub async fn run ( self ) -> anyhow:: Result < ( ) > {
7676 log:: debug!( "creating new client: {}" , self . common. name) ;
7777
78- let mut config = Config :: load ( self . config . as_deref ( ) ) ?;
79-
80- if !self . common . force && config. clients . contains_key ( & self . common . name ) {
81- bail ! (
82- "A client named '{}' already exists. You need to delete it first or use --force" ,
83- self . common. name
84- ) ;
85- }
86-
87- let http = create_client ( & self . http ) . await ?;
88-
89- let provider_metadata =
90- CoreProviderMetadata :: discover_async ( self . common . issuer . clone ( ) , & http) . await ?;
91-
92- let client = CoreClient :: from_provider_metadata (
93- provider_metadata,
94- ClientId :: new ( self . client_id . clone ( ) ) ,
95- self . client_secret . clone ( ) . map ( ClientSecret :: new) ,
96- ) ;
97-
98- let token = match self . refresh_token {
99- None => self . code_flow ( & http, & client) . await ?,
100- Some ( refresh_token) => {
101- refresh_token_request ( & http, & client, self . common . scope . as_deref ( ) , refresh_token)
102- . await ?
78+ Config :: locked ( self . config . as_deref ( ) , async |config| {
79+ if !self . common . force && config. clients . contains_key ( & self . common . name ) {
80+ bail ! (
81+ "A client named '{}' already exists. You need to delete it first or use --force" ,
82+ self . common. name
83+ ) ;
10384 }
104- } ;
105-
106- // log info
107-
108- log:: info!( "First token:" ) ;
109- log:: info!(
110- " ID: {}" ,
111- OrNone (
112- & token
113- . extra_fields( )
114- . id_token( )
115- . cloned( )
116- . map( |t| t. to_string( ) )
117- )
118- ) ;
119- log:: info!( " Access: {}" , token. access_token( ) . clone( ) . into_secret( ) ) ;
120- log:: info!(
121- " Refresh: {}" ,
122- OrNone ( & token. refresh_token( ) . cloned( ) . map( |t| t. into_secret( ) ) )
123- ) ;
12485
125- // create client
86+ let http = create_client ( & self . http ) . await ? ;
12687
127- let client = Client {
128- issuer_url : self . common . issuer ,
129- scope : self . common . scope ,
130- r#type : ClientType :: Public {
131- client_id : self . client_id ,
132- client_secret : self . client_secret ,
133- } ,
134- state : Some ( token. into ( ) ) ,
135- } ;
88+ let provider_metadata =
89+ CoreProviderMetadata :: discover_async ( self . common . issuer . clone ( ) , & http) . await ?;
13690
137- config
138- . clients
139- . insert ( self . common . name . clone ( ) , client. clone ( ) ) ;
91+ let client = CoreClient :: from_provider_metadata (
92+ provider_metadata,
93+ ClientId :: new ( self . client_id . clone ( ) ) ,
94+ self . client_secret . clone ( ) . map ( ClientSecret :: new) ,
95+ ) ;
14096
141- config. store ( self . config . as_deref ( ) ) ?;
97+ let token = match & self . refresh_token {
98+ None => self . code_flow ( & http, & client) . await ?,
99+ Some ( refresh_token) => {
100+ refresh_token_request (
101+ & http,
102+ & client,
103+ self . common . scope . as_deref ( ) ,
104+ refresh_token. clone ( ) ,
105+ )
106+ . await ?
107+ }
108+ } ;
109+
110+ log:: info!( "First token:" ) ;
111+ log:: info!(
112+ " ID: {}" ,
113+ OrNone (
114+ & token
115+ . extra_fields( )
116+ . id_token( )
117+ . cloned( )
118+ . map( |t| t. to_string( ) )
119+ )
120+ ) ;
121+ log:: info!( " Access: {}" , token. access_token( ) . clone( ) . into_secret( ) ) ;
122+ log:: info!(
123+ " Refresh: {}" ,
124+ OrNone ( & token. refresh_token( ) . cloned( ) . map( |t| t. into_secret( ) ) )
125+ ) ;
142126
143- Ok ( ( ) )
127+ let client = Client {
128+ issuer_url : self . common . issuer . clone ( ) ,
129+ scope : self . common . scope . clone ( ) ,
130+ r#type : ClientType :: Public {
131+ client_id : self . client_id . clone ( ) ,
132+ client_secret : self . client_secret . clone ( ) ,
133+ } ,
134+ state : Some ( token. into ( ) ) ,
135+ } ;
136+
137+ config
138+ . clients
139+ . insert ( self . common . name . clone ( ) , client. clone ( ) ) ;
140+
141+ Ok ( ( ) )
142+ } )
143+ . await
144144 }
145145
146146 fn bind_mode ( & self ) -> Bind {
@@ -191,12 +191,8 @@ Open the following URL in your browser and perform the interactive login process
191191 ) ;
192192 }
193193
194- // receive the result from the local server
195-
196194 let result = server. receive_token ( ) . await ?;
197195
198- // validate CSRF token
199-
200196 match result. state {
201197 None => {
202198 bail ! ( "missing 'state' parameter from server" ) ;
@@ -207,16 +203,12 @@ Open the following URL in your browser and perform the interactive login process
207203 Some ( _) => { }
208204 }
209205
210- // fetch token
211-
212206 let token = client
213207 . exchange_code ( AuthorizationCode :: new ( result. code ) ) ?
214208 . set_pkce_verifier ( pkce_verifier)
215209 . request_async ( http)
216210 . await ?;
217211
218- // check ID token
219-
220212 if let Some ( id_token) = token. extra_fields ( ) . id_token ( ) {
221213 let scopes = self . common . scope . as_deref ( ) ;
222214 let verifier =
0 commit comments