6
6
using Microsoft . AspNetCore . Http ;
7
7
using Microsoft . Extensions . Logging ;
8
8
using Microsoft . Extensions . Options ;
9
+ using Microsoft . Extensions . Primitives ;
9
10
10
11
namespace Slackbot . Net . Endpoints . Authentication ;
11
12
@@ -31,22 +32,28 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
31
32
32
33
string timestamp = headers [ TimestampHeaderName ] . FirstOrDefault ( ) ;
33
34
string signature = headers [ SignatureHeaderName ] . FirstOrDefault ( ) ;
34
-
35
+ var failures = new StringBuilder ( ) ;
35
36
if ( timestamp == null )
36
37
{
37
- return HandleRequestResult . Fail ( $ "Missing header { TimestampHeaderName } ") ;
38
+ failures . Append ( $ "Missing header { TimestampHeaderName } ") ;
38
39
}
39
40
40
41
if ( signature == null )
41
42
{
42
- return HandleRequestResult . Fail ( $ "Missing header { SignatureHeaderName } ") ;
43
+ failures . Append ( $ "Missing header { TimestampHeaderName } ") ;
44
+ }
45
+
46
+ if ( timestamp is null || signature == null )
47
+ {
48
+ Logger . LogDebug ( $ "Skipping handler: { failures } ") ;
49
+ return HandleRequestResult . SkipHandler ( ) ;
43
50
}
44
51
45
52
bool isNumber = long . TryParse ( timestamp , out long timestampAsLong ) ;
46
53
47
54
if ( ! isNumber )
48
55
{
49
- return HandleRequestResult . Fail ( $ "Invalid header. Header { TimestampHeaderName } not a number") ;
56
+ return HandleRequestResult . Fail ( $ "Invalid formatted headers. { TimestampHeaderName } is not a number. ") ;
50
57
}
51
58
52
59
Request . EnableBuffering ( ) ;
@@ -59,7 +66,7 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
59
66
return HandleRequestResult . Success ( new AuthenticationTicket ( new ClaimsPrincipal ( ) , SlackbotEventsAuthenticationConstants . AuthenticationScheme ) ) ;
60
67
}
61
68
62
- return HandleRequestResult . Fail ( "Verification of Slack request failed." ) ;
69
+ return HandleRequestResult . Fail ( "Slack request failed signature verification ." ) ;
63
70
64
71
}
65
72
0 commit comments