# 웹훅의 Discourse 서명 매개변수

**URL:** https://meta.discourse.org/t/discourse-signing-parameters-in-webhooks/134415
**Category:** Feature
**Created:** [11월 26, 2019, 5:11오전 UTC](https://meta.discourse.org/t/discourse-signing-parameters-in-webhooks/134415 "2019-11-26T05:11:13Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![EGreg](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/egreg/32/133614_2.png) [@EGreg](https://meta.discourse.org/u/EGreg)
#### Post date: [11월 26, 2019, 5:11오전 UTC](https://meta.discourse.org/t/discourse-signing-parameters-in-webhooks/134415/1 "2019-11-26T05:11:13Z")

</div>

안녕하세요. 사용자가 생성되거나 업데이트될 때 Discourse 웹훅을 사용하길 원합니다. 다만, Discourse에서 전송되는 데이터를 신뢰할 수 있도록 하고 싶습니다. 공개-비공개 키 쌍을 지원하거나, 최소한 서명된 페이로드를 검증할 수 있는 대칭 시크릿 키를 사용할 수 있는 방법이 있을까요? 또한, 모든 페이로드에 서명하는 표준 프레임워크와 이를 직렬화하고 서명을 검증하는 표준 PHP 구현체(예)를 제공해 주실 수 있을까요?

Facebook은 사용자 정보를 전송할 때 이렇게 합니다. 이를 통해 다른 소프트웨어가 Discourse의 사용자 및 기타 객체와 통합할 수 있게 됩니다.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [11월 26, 2019, 5:02오후 UTC](https://meta.discourse.org/t/discourse-signing-parameters-in-webhooks/134415/2 "2019-11-26T17:02:25Z")

</div>

> [@EGreg](#):
>
> 또는 적어도 대칭 시크릿 키,

웹훅 시크릿 키가 찾으시는 것과 비슷합니까? [WP Discourse](https://github.com/discourse/wp-discourse) 플러그인이 WordPress에 설정된 웹훅 시크릿과 이를 검증하는 방법은 다음과 같습니다:

```php
public function verify_discourse_webhook_request( $data ) {
	$options = $this->get_options();
	// X-Discourse-Event-Signature는 'sha256=' . 원본 페이로드의 hmac로 구성됩니다.
	// `hash_hmac( 'sha256', $payload, $secret )`을 계산하여 생성됩니다.
	$sig = substr( $data->get_header( 'X-Discourse-Event-Signature' ), 7 );
	if ( $sig ) {
		$payload = $data->get_body();
		// 요청을 검증하는 데 사용되는 키 - Discourse 웹훅에 일치하는 키가 설정되어 있어야 합니다.
		$secret = ! empty( $options['webhook-secret'] ) ? $options['webhook-secret'] : '';

		if ( ! $secret ) {

			return new \WP_Error( 'discourse_webhook_configuration_error', '웹훅 시크릿 키가 설정되지 않았습니다.' );
		}

		if ( hash_hmac( 'sha256', $payload, $secret ) === $sig ) {

			return $data;
		} else {

			return new \WP_Error( 'discourse_webhook_authentication_error', 'Discourse 웹훅 요청 오류: 서명이 일치하지 않습니다.' );
		}
	}

	return new \WP_Error( 'discourse_webhook_authentication_error', 'Discourse 웹훅 요청 오류: 요청에 대해 X-Discourse-Event-Signature가 설정되지 않았습니다.' );
}

```
