Class: TxghServer::GithubRequestAuth

Inherits:
Object
  • Object
show all
Defined in:
lib/txgh-server/github_request_auth.rb

Constant Summary collapse

HMAC_DIGEST =
OpenSSL::Digest.new('sha1')
RACK_HEADER =
'HTTP_X_HUB_SIGNATURE'
GITHUB_HEADER =
'X-Hub-Signature'

Class Method Summary collapse

Class Method Details

.authentic_request?(request, secret) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
# File 'lib/txgh-server/github_request_auth.rb', line 10

def authentic_request?(request, secret)
  request.body.rewind
  expected_signature = compute_signature(request.body.read, secret)
  actual_signature = request.env[RACK_HEADER]
  actual_signature == expected_signature
end

.compute_signature(content, secret) ⇒ Object



17
18
19
# File 'lib/txgh-server/github_request_auth.rb', line 17

def compute_signature(content, secret)
  "sha1=#{digest(content, secret)}"
end