/** @test */ public function should_return_true_on_successful_attempt_with_custom_prefix() { $params = ['name' => 'Philip Brown']; $token = new Token('abc123', 'qwerty'); $request = new Request('POST', 'users', $params); $signed = $request->sign($token, 'x-'); $params = array_merge($params, $signed); $token = new Token('abc123', 'qwerty'); $auth = new Auth('POST', 'users', $params, [new CheckKey(), new CheckVersion(), new CheckTimestamp(), new CheckSignature()]); $this->assertTrue($auth->attempt($token, 'x-')); }
/** * Authenticates a request * @param string $key * @param string $secret */ public function auth($key, $secret) { //make sure we have the require attributes $required = array('timestamp'); $data = $this->getData(); foreach ($required as $require) { if (!isset($data[$this->prefix . $require])) { return false; } } //looks good, now let's process it $auth = new Auth($this->getMethod(), $this->getRoute(), $this->getData(), [new CheckKey(), new CheckVersion(), new CheckTimestamp(), new CheckSignature()]); $token = new Token($key, $secret); try { return $auth->attempt($token, $this->prefix); } catch (SignatureException $e) { return false; } }