19
19
using RestSharp . Extensions ;
20
20
using RestSharp . Validation ;
21
21
22
- namespace RestSharp . Authenticators . OAuth
23
- {
22
+ namespace RestSharp . Authenticators . OAuth {
24
23
/// <summary>
25
24
/// A class to encapsulate OAuth authentication flow.
26
25
/// </summary>
27
- sealed class OAuthWorkflow
28
- {
26
+ sealed class OAuthWorkflow {
29
27
public string Version { get ; set ; }
30
28
31
29
public string ConsumerKey { get ; set ; }
@@ -64,8 +62,7 @@ sealed class OAuthWorkflow
64
62
/// <param name="method">The HTTP method for the intended request</param>
65
63
/// <param name="parameters">Any existing, non-OAuth query parameters desired in the request</param>
66
64
/// <returns></returns>
67
- public OAuthParameters BuildRequestTokenInfo ( string method , WebPairCollection parameters )
68
- {
65
+ public OAuthParameters BuildRequestTokenInfo ( string method , WebPairCollection parameters ) {
69
66
ValidateTokenRequestState ( ) ;
70
67
71
68
var allParameters = new WebPairCollection ( ) ;
@@ -79,8 +76,7 @@ public OAuthParameters BuildRequestTokenInfo(string method, WebPairCollection pa
79
76
80
77
var signatureBase = OAuthTools . ConcatenateRequestElements ( method , RequestTokenUrl , allParameters ) ;
81
78
82
- return new OAuthParameters
83
- {
79
+ return new OAuthParameters {
84
80
Signature = OAuthTools . GetSignature ( SignatureMethod , SignatureTreatment , signatureBase , ConsumerSecret ) ,
85
81
Parameters = authParameters
86
82
} ;
@@ -93,8 +89,7 @@ public OAuthParameters BuildRequestTokenInfo(string method, WebPairCollection pa
93
89
/// </summary>
94
90
/// <param name="method">The HTTP method for the intended request</param>
95
91
/// <param name="parameters">Any existing, non-OAuth query parameters desired in the request</param>
96
- public OAuthParameters BuildAccessTokenSignature ( string method , WebPairCollection parameters )
97
- {
92
+ public OAuthParameters BuildAccessTokenSignature ( string method , WebPairCollection parameters ) {
98
93
ValidateAccessRequestState ( ) ;
99
94
100
95
var allParameters = new WebPairCollection ( ) ;
@@ -109,8 +104,7 @@ public OAuthParameters BuildAccessTokenSignature(string method, WebPairCollectio
109
104
110
105
var signatureBase = OAuthTools . ConcatenateRequestElements ( method , uri . ToString ( ) , allParameters ) ;
111
106
112
- return new OAuthParameters
113
- {
107
+ return new OAuthParameters {
114
108
Signature = OAuthTools . GetSignature ( SignatureMethod , SignatureTreatment , signatureBase , ConsumerSecret , TokenSecret ) ,
115
109
Parameters = authParameters
116
110
} ;
@@ -123,8 +117,7 @@ public OAuthParameters BuildAccessTokenSignature(string method, WebPairCollectio
123
117
/// </summary>
124
118
/// <param name="method">The HTTP method for the intended request</param>
125
119
/// <param name="parameters">Any existing, non-OAuth query parameters desired in the request</param>
126
- public OAuthParameters BuildClientAuthAccessTokenSignature ( string method , WebPairCollection parameters )
127
- {
120
+ public OAuthParameters BuildClientAuthAccessTokenSignature ( string method , WebPairCollection parameters ) {
128
121
ValidateClientAuthAccessRequestState ( ) ;
129
122
130
123
var allParameters = new WebPairCollection ( ) ;
@@ -139,15 +132,13 @@ public OAuthParameters BuildClientAuthAccessTokenSignature(string method, WebPai
139
132
140
133
var signatureBase = OAuthTools . ConcatenateRequestElements ( method , uri . ToString ( ) , allParameters ) ;
141
134
142
- return new OAuthParameters
143
- {
135
+ return new OAuthParameters {
144
136
Signature = OAuthTools . GetSignature ( SignatureMethod , SignatureTreatment , signatureBase , ConsumerSecret ) ,
145
137
Parameters = authParameters
146
138
} ;
147
139
}
148
140
149
- public OAuthParameters BuildProtectedResourceSignature ( string method , WebPairCollection parameters , string url )
150
- {
141
+ public OAuthParameters BuildProtectedResourceSignature ( string method , WebPairCollection parameters , string url ) {
151
142
ValidateProtectedResourceState ( ) ;
152
143
153
144
var allParameters = new WebPairCollection ( ) ;
@@ -167,42 +158,35 @@ public OAuthParameters BuildProtectedResourceSignature(string method, WebPairCol
167
158
168
159
var signatureBase = OAuthTools . ConcatenateRequestElements ( method , url , allParameters ) ;
169
160
170
- return new OAuthParameters
171
- {
161
+ return new OAuthParameters {
172
162
Signature = OAuthTools . GetSignature ( SignatureMethod , SignatureTreatment , signatureBase , ConsumerSecret , TokenSecret ) ,
173
163
Parameters = authParameters
174
164
} ;
175
165
}
176
166
177
- void ValidateTokenRequestState ( )
178
- {
167
+ void ValidateTokenRequestState ( ) {
179
168
Ensure . NotEmpty ( RequestTokenUrl , nameof ( RequestTokenUrl ) ) ;
180
169
Ensure . NotEmpty ( ConsumerKey , nameof ( ConsumerKey ) ) ;
181
170
}
182
171
183
- void ValidateAccessRequestState ( )
184
- {
172
+ void ValidateAccessRequestState ( ) {
185
173
Ensure . NotEmpty ( AccessTokenUrl , nameof ( AccessTokenUrl ) ) ;
186
174
Ensure . NotEmpty ( ConsumerKey , nameof ( ConsumerKey ) ) ;
187
175
Ensure . NotEmpty ( Token , nameof ( Token ) ) ;
188
176
}
189
177
190
- void ValidateClientAuthAccessRequestState ( )
191
- {
178
+ void ValidateClientAuthAccessRequestState ( ) {
192
179
Ensure . NotEmpty ( AccessTokenUrl , nameof ( AccessTokenUrl ) ) ;
193
180
Ensure . NotEmpty ( ConsumerKey , nameof ( ConsumerKey ) ) ;
194
181
Ensure . NotEmpty ( ClientUsername , nameof ( ClientUsername ) ) ;
195
182
}
196
183
197
- void ValidateProtectedResourceState ( )
198
- {
184
+ void ValidateProtectedResourceState ( ) {
199
185
Ensure . NotEmpty ( ConsumerKey , nameof ( ConsumerKey ) ) ;
200
186
}
201
187
202
- WebPairCollection GenerateAuthParameters ( string timestamp , string nonce )
203
- {
204
- var authParameters = new WebPairCollection
205
- {
188
+ WebPairCollection GenerateAuthParameters ( string timestamp , string nonce ) {
189
+ var authParameters = new WebPairCollection {
206
190
new WebPair ( "oauth_consumer_key" , ConsumerKey ) ,
207
191
new WebPair ( "oauth_nonce" , nonce ) ,
208
192
new WebPair ( "oauth_signature_method" , SignatureMethod . ToRequestValue ( ) ) ,
@@ -222,8 +206,7 @@ WebPairCollection GenerateAuthParameters(string timestamp, string nonce)
222
206
}
223
207
224
208
WebPairCollection GenerateXAuthParameters ( string timestamp , string nonce )
225
- => new WebPairCollection
226
- {
209
+ => new WebPairCollection {
227
210
new WebPair ( "x_auth_username" , ClientUsername ) ,
228
211
new WebPair ( "x_auth_password" , ClientPassword ) ,
229
212
new WebPair ( "x_auth_mode" , "client_auth" ) ,
@@ -234,10 +217,9 @@ WebPairCollection GenerateXAuthParameters(string timestamp, string nonce)
234
217
new WebPair ( "oauth_version" , Version ?? "1.0" )
235
218
} ;
236
219
237
- internal class OAuthParameters
238
- {
220
+ internal class OAuthParameters {
239
221
public WebPairCollection Parameters { get ; set ; }
240
222
public string Signature { get ; set ; }
241
223
}
242
224
}
243
- }
225
+ }
0 commit comments