PhilipBrown\Signature\Auth::attempt PHP Method

attempt() public method

Attempt to authenticate a request
public attempt ( Token $token, string $prefix = Request::PREFIX ) : boolean
$token Token
$prefix string
return boolean
    public function attempt(Token $token, $prefix = Request::PREFIX)
    {
        $auth = $this->getAuthParams($prefix);
        $body = $this->getBodyParams($prefix);
        $request = new Request($this->method, $this->uri, $body, $auth[$prefix . 'timestamp']);
        $signature = $request->sign($token, $prefix);
        foreach ($this->guards as $guard) {
            $guard->check($auth, $signature, $prefix);
        }
        return true;
    }

Usage Example

Example #1
0
 /** @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-'));
 }
All Usage Examples Of PhilipBrown\Signature\Auth::attempt