@@ -15,31 +15,44 @@ const ZOOM_SECRET =
1515 process . env . TEST_ZOOM_WEBHOOK_SECRET_TOKEN ||
1616 process . env . ZOOM_WEBHOOK_SECRET_TOKEN ;
1717
18+ const ZOOM_AUTH =
19+ process . env . TEST_ZOOM_WEBHOOK_AUTH || process . env . ZOOM_WEBHOOK_AUTH ;
20+
1821const handler = async function ( event , context ) {
1922 try {
20- const message = `v0:${ event . headers [ 'x-zm-request-timestamp' ] } :${ event . body } ` ;
23+ /**
24+ * verification. zoom will either send an authorization header or a x-zm-signature header
25+ */
2126
22- const hashForVerify = crypto
23- . createHmac ( 'sha256' , ZOOM_SECRET )
24- . update ( message )
25- . digest ( 'hex' ) ;
27+ let authorized = false ;
2628
27- const signature = `v0=${ hashForVerify } ` ;
29+ if ( event . headers [ 'x-zm-signature' ] ) {
30+ const message = `v0:${ event . headers [ 'x-zm-request-timestamp' ] } :${ event . body } ` ;
2831
29- console . log ( 'headers' ) ;
30- console . log ( event . headers ) ;
31- console . log (
32- event . headers . get ? event . headers . get ( 'x-zm-signature' ) : 'no headers.get'
33- ) ;
32+ const hashForVerify = crypto
33+ . createHmac ( 'sha256' , ZOOM_SECRET )
34+ . update ( message )
35+ . digest ( 'hex' ) ;
36+
37+ const signature = `v0=${ hashForVerify } ` ;
3438
35- console . log ( 'message' ) ;
36- console . log ( message ) ;
37- console . log ( 'signature' ) ;
38- console . log ( signature ) ;
39- console . log ( 'x-zm-signature' ) ;
40- console . log ( event . headers [ 'x-zm-signature' ] ) ;
39+ console . log ( 'message' ) ;
40+ console . log ( message ) ;
41+ console . log ( 'signature' ) ;
42+ console . log ( signature ) ;
43+ console . log ( 'x-zm-signature' ) ;
44+ console . log ( event . headers [ 'x-zm-signature' ] ) ;
45+
46+ if ( event . headers [ 'x-zm-signature' ] === signature ) {
47+ authorized = true ;
48+ }
49+ } else {
50+ if ( event . headers . authorization === ZOOM_AUTH ) {
51+ authorized = true ;
52+ }
53+ }
4154
42- if ( event . headers [ 'x-zm-signature' ] !== signature ) {
55+ if ( ! authorized ) {
4356 console . log ( 'Unauthorized' , event ) ;
4457 return {
4558 statusCode : 401 ,
0 commit comments