@@ -76,19 +76,11 @@ public async Task ApplyAsync(HttpRequestMessage request, CancellationToken cance
7676
7777 private async Task < TokenData > PerformDeviceLoginAsync ( CancellationToken cancellationToken )
7878 {
79- var codeRequestForm = new Dictionary < string , string >
80- {
81- { "client_id" , _clientId } ,
82- { "scope" , _scope }
83- } ;
84-
85- // RFC 8707: Add resource parameter if configured
86- if ( ! string . IsNullOrEmpty ( _resourceUrl ) )
87- {
88- codeRequestForm [ "resource" ] = _resourceUrl ;
89- }
90-
91- var codeRequest = new FormUrlEncodedContent ( codeRequestForm ) ;
79+ var codeRequest = FormUrlEncoded . Create ( )
80+ . Add ( "client_id" , _clientId )
81+ . Add ( "scope" , _scope )
82+ . AddIfNotEmpty ( "resource" , _resourceUrl ) // RFC 8707
83+ . ToContent ( ) ;
9284
9385 var codeResponse = await _httpClient . PostAsync ( _deviceCodeEndpoint , codeRequest , cancellationToken ) ;
9486 codeResponse . EnsureSuccessStatusCode ( ) ;
@@ -105,20 +97,12 @@ private async Task<TokenData> PerformDeviceLoginAsync(CancellationToken cancella
10597 {
10698 await Task . Delay ( interval * 1000 , cancellationToken ) ;
10799
108- var tokenRequestForm = new Dictionary < string , string >
109- {
110- { "grant_type" , "urn:ietf:params:oauth:grant-type:device_code" } ,
111- { "client_id" , _clientId } ,
112- { "device_code" , codeData . device_code }
113- } ;
114-
115- // RFC 8707: Add resource parameter if configured
116- if ( ! string . IsNullOrEmpty ( _resourceUrl ) )
117- {
118- tokenRequestForm [ "resource" ] = _resourceUrl ;
119- }
120-
121- var tokenRequest = new FormUrlEncodedContent ( tokenRequestForm ) ;
100+ var tokenRequest = FormUrlEncoded . Create ( )
101+ . Add ( "grant_type" , "urn:ietf:params:oauth:grant-type:device_code" )
102+ . Add ( "client_id" , _clientId )
103+ . Add ( "device_code" , codeData . device_code )
104+ . AddIfNotEmpty ( "resource" , _resourceUrl ) // RFC 8707
105+ . ToContent ( ) ;
122106
123107 var tokenResponse = await _httpClient . PostAsync ( _tokenEndpoint , tokenRequest , cancellationToken ) ;
124108
@@ -144,20 +128,12 @@ private async Task<TokenData> PerformDeviceLoginAsync(CancellationToken cancella
144128
145129 private async Task < TokenData > RefreshTokenAsync ( string refreshToken , CancellationToken cancellationToken )
146130 {
147- var form = new Dictionary < string , string >
148- {
149- { "grant_type" , "refresh_token" } ,
150- { "client_id" , _clientId } ,
151- { "refresh_token" , refreshToken }
152- } ;
153-
154- // RFC 8707: Add resource parameter if configured
155- if ( ! string . IsNullOrEmpty ( _resourceUrl ) )
156- {
157- form [ "resource" ] = _resourceUrl ;
158- }
159-
160- var content = new FormUrlEncodedContent ( form ) ;
131+ var content = FormUrlEncoded . Create ( )
132+ . Add ( "grant_type" , "refresh_token" )
133+ . Add ( "client_id" , _clientId )
134+ . Add ( "refresh_token" , refreshToken )
135+ . AddIfNotEmpty ( "resource" , _resourceUrl ) // RFC 8707
136+ . ToContent ( ) ;
161137
162138 var response = await _httpClient . PostAsync ( _tokenEndpoint , content , cancellationToken ) ;
163139 response . EnsureSuccessStatusCode ( ) ;
0 commit comments