1616using RestSharp . Extensions ;
1717using System . Web ;
1818
19+ // ReSharper disable NotResolvedInText
1920// ReSharper disable CheckNamespace
2021
2122namespace RestSharp . Authenticators ;
@@ -38,7 +39,7 @@ public class OAuth1Authenticator : IAuthenticator {
3839 public virtual string ? ClientUsername { get ; set ; }
3940 public virtual string ? ClientPassword { get ; set ; }
4041
41- public ValueTask Authenticate ( RestClient client , RestRequest request ) {
42+ public ValueTask Authenticate ( IRestClient client , RestRequest request ) {
4243 var workflow = new OAuthWorkflow {
4344 ConsumerKey = ConsumerKey ,
4445 ConsumerSecret = ConsumerSecret ,
@@ -64,8 +65,8 @@ public static OAuth1Authenticator ForRequestToken(
6465 string consumerKey ,
6566 string ? consumerSecret ,
6667 OAuthSignatureMethod signatureMethod = OAuthSignatureMethod . HmacSha1
67- ) {
68- var authenticator = new OAuth1Authenticator {
68+ )
69+ => new ( ) {
6970 ParameterHandling = OAuthParameterHandling . HttpAuthorizationHeader ,
7071 SignatureMethod = signatureMethod ,
7172 SignatureTreatment = OAuthSignatureTreatment . Escaped ,
@@ -74,10 +75,6 @@ public static OAuth1Authenticator ForRequestToken(
7475 Type = OAuthType . RequestToken
7576 } ;
7677
77- return authenticator ;
78- }
79-
80- [ PublicAPI ]
8178 public static OAuth1Authenticator ForRequestToken ( string consumerKey , string ? consumerSecret , string callbackUrl ) {
8279 var authenticator = ForRequestToken ( consumerKey , consumerSecret ) ;
8380
@@ -105,7 +102,6 @@ public static OAuth1Authenticator ForAccessToken(
105102 Type = OAuthType . AccessToken
106103 } ;
107104
108- [ PublicAPI ]
109105 public static OAuth1Authenticator ForAccessToken (
110106 string consumerKey ,
111107 string ? consumerSecret ,
@@ -171,7 +167,6 @@ public static OAuth1Authenticator ForClientAuthentication(
171167 Type = OAuthType . ClientAuthentication
172168 } ;
173169
174- [ PublicAPI ]
175170 public static OAuth1Authenticator ForProtectedResource (
176171 string consumerKey ,
177172 string ? consumerSecret ,
@@ -190,7 +185,7 @@ public static OAuth1Authenticator ForProtectedResource(
190185 TokenSecret = accessTokenSecret
191186 } ;
192187
193- void AddOAuthData ( RestClient client , RestRequest request , OAuthWorkflow workflow ) {
188+ void AddOAuthData ( IRestClient client , RestRequest request , OAuthWorkflow workflow ) {
194189 var requestUrl = client . BuildUriWithoutQueryParameters ( request ) . AbsoluteUri ;
195190
196191 if ( requestUrl . Contains ( '?' ) )
@@ -201,11 +196,9 @@ void AddOAuthData(RestClient client, RestRequest request, OAuthWorkflow workflow
201196 var url = client . BuildUri ( request ) . ToString ( ) ;
202197 var queryStringStart = url . IndexOf ( '?' ) ;
203198
204- if ( queryStringStart != - 1 )
205- url = url . Substring ( 0 , queryStringStart ) ;
206-
207- var method = request . Method . ToString ( ) . ToUpperInvariant ( ) ;
199+ if ( queryStringStart != - 1 ) url = url . Substring ( 0 , queryStringStart ) ;
208200
201+ var method = request . Method . ToString ( ) . ToUpperInvariant ( ) ;
209202 var parameters = new WebPairCollection ( ) ;
210203
211204 // include all GET and POST parameters before generating the signature
@@ -247,21 +240,18 @@ void AddOAuthData(RestClient client, RestRequest request, OAuthWorkflow workflow
247240
248241 request . AddOrUpdateParameters ( oauthParameters ) ;
249242
250- IEnumerable < Parameter > CreateHeaderParameters ( )
251- => new [ ] { new HeaderParameter ( KnownHeaders . Authorization , GetAuthorizationHeader ( ) ) } ;
243+ IEnumerable < Parameter > CreateHeaderParameters ( ) => new [ ] { new HeaderParameter ( KnownHeaders . Authorization , GetAuthorizationHeader ( ) ) } ;
252244
253- IEnumerable < Parameter > CreateUrlParameters ( )
254- => oauth . Parameters . Select ( p => new GetOrPostParameter ( p . Name , HttpUtility . UrlDecode ( p . Value ) ) ) ;
245+ IEnumerable < Parameter > CreateUrlParameters ( ) => oauth . Parameters . Select ( p => new GetOrPostParameter ( p . Name , HttpUtility . UrlDecode ( p . Value ) ) ) ;
255246
256247 string GetAuthorizationHeader ( ) {
257248 var oathParameters =
258249 oauth . Parameters
259250 . OrderBy ( x => x , WebPair . Comparer )
260- . Select ( x => $ " { x . Name } = \" { x . WebValue } \" " )
251+ . Select ( x => x . GetQueryParameter ( true ) )
261252 . ToList ( ) ;
262253
263- if ( ! Realm . IsEmpty ( ) )
264- oathParameters . Insert ( 0 , $ "realm=\" { OAuthTools . UrlEncodeRelaxed ( Realm ! ) } \" ") ;
254+ if ( ! Realm . IsEmpty ( ) ) oathParameters . Insert ( 0 , $ "realm=\" { OAuthTools . UrlEncodeRelaxed ( Realm ) } \" ") ;
265255
266256 return $ "OAuth { string . Join ( "," , oathParameters ) } ";
267257 }
@@ -270,5 +260,5 @@ string GetAuthorizationHeader() {
270260
271261static class ParametersExtensions {
272262 internal static IEnumerable < WebPair > ToWebParameters ( this IEnumerable < Parameter > p )
273- => p . Select ( x => new WebPair ( Ensure . NotNull ( x . Name , "Parameter name" ) , Ensure . NotNull ( x . Value , "Parameter value" ) . ToString ( ) ! ) ) ;
274- }
263+ => p . Select ( x => new WebPair ( Ensure . NotNull ( x . Name , "Parameter name" ) , x . Value ? . ToString ( ) ) ) ;
264+ }
0 commit comments