@@ -11,10 +11,13 @@ namespace DocuSign.CodeExamples
11
11
using System . Net . Http ;
12
12
using System . Net . Http . Headers ;
13
13
using System . Security . Claims ;
14
+ using System . Security . Cryptography ;
15
+ using System . Text ;
14
16
using System . Text . Json ;
15
17
using System . Text . RegularExpressions ;
16
18
using System . Threading . Tasks ;
17
19
using System . Web ;
20
+ using Azure . Core ;
18
21
using DocuSign . CodeExamples . Common ;
19
22
using DocuSign . CodeExamples . Models ;
20
23
using DocuSign . Rooms . Api ;
@@ -179,14 +182,17 @@ public void ConfigureServices(IServiceCollection services)
179
182
options . ClaimActions . MapJsonKey ( "access_token" , "access_token" ) ;
180
183
options . ClaimActions . MapJsonKey ( "refresh_token" , "refresh_token" ) ;
181
184
options . ClaimActions . MapJsonKey ( "expires_in" , "expires_in" ) ;
185
+
182
186
options . Events = new OAuthEvents
183
187
{
184
188
OnRedirectToAuthorizationEndpoint = redirectContext =>
185
189
{
186
190
List < string > scopesForCurrentApi = this . apiTypes . GetValueOrDefault ( Enum . Parse < ExamplesApiType > ( this . Configuration [ "API" ] ) ) ;
187
-
188
191
redirectContext . RedirectUri = this . UpdateRedirectUriScopes ( redirectContext . RedirectUri , scopesForCurrentApi ) ;
189
192
193
+ redirectContext . Options . UsePkce = this . Configuration [ "PkceFailed" ] == null ;
194
+
195
+ this . Configuration [ "RedirectUrl" ] = redirectContext . RedirectUri ;
190
196
redirectContext . HttpContext . Response . Redirect ( redirectContext . RedirectUri ) ;
191
197
return Task . FromResult ( 0 ) ;
192
198
} ,
@@ -206,11 +212,28 @@ public void ConfigureServices(IServiceCollection services)
206
212
context . RunClaimActions ( payload . RootElement ) ;
207
213
}
208
214
} ,
209
- OnRemoteFailure = context =>
215
+ OnRemoteFailure = async context =>
210
216
{
211
- context . HandleResponse ( ) ;
212
- context . Response . Redirect ( "/Home/Error?message=" + context . Failure ? . Message ) ;
213
- return Task . FromResult ( 0 ) ;
217
+ if ( this . Configuration [ "PkceFailed" ] != null )
218
+ {
219
+ context . HandleResponse ( ) ;
220
+ context . Response . Redirect ( "/Home/Error?message=" + context . Failure ? . Message ) ;
221
+ }
222
+ else
223
+ {
224
+ var redirectContext = new RedirectContext < OAuthOptions > (
225
+ context . HttpContext ,
226
+ context . Scheme ,
227
+ options ,
228
+ context . Properties ,
229
+ this . Configuration [ "RedirectUrl" ] ) ;
230
+
231
+ this . Configuration [ "PkceFailed" ] = "true" ;
232
+
233
+ await options . Events . OnRedirectToAuthorizationEndpoint ( redirectContext ) ;
234
+
235
+ context . HandleResponse ( ) ;
236
+ }
214
237
} ,
215
238
} ;
216
239
} ) ;
0 commit comments