Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADD README.md and docblock #8

Merged
merged 6 commits into from
Oct 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/.idea/
/.idea/*
/vendor/
9 changes: 0 additions & 9 deletions .idea/modules.xml

This file was deleted.

207 changes: 0 additions & 207 deletions .idea/workspace.xml

This file was deleted.

66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# hash-verifier

hash verification using a nonce & verifying the hmac from the URL for a laravel application

## Installation

```bash
composer require dpc/hash-verifier
```

The service provider will be automatically discovered in Laravel 5.5. Publish the config file by running:
```bash
php artisan vendor:publish --provider="Dpc\HashVerifier\AuthValidatorServiceProvider"
```

This will create a `validator.php` in your config folder. The key indicates the attribute in your `User` table where you are storing the nonce.

> Do not use your secret directly in config file. Instead fetch it from the `.env` or server environment variables.

## Usage
Inject the validator contract in your class:
```php
public function __construct(AuthValidatorContract $validator)
{
$this->validator = $validator;
}
```
To generate a nonce:
```php
$nonce = $this->validator->generateNonce($user)
```
Ensure that you do not mutate the nonce.


To verify whether the nonce matches,

```php
$nonceMatches = $this->validator->matches($user, $nonce);
```

To validate if the hmac matches the components of the URL:

```php
$result = $this->validator->validate($uriComponents));
```

You can check this [repo](https://github.com/themeanorak/laravel-shopify/blob/master/src/Modules/Auth.php) for further details on how to use this package

### Versioning
This package follows [semver](http://semver.org/). Features introduced & any breaking changes created in major releases are mentioned in [releases](https://github.com/Dylan-DPC/hash-verifier/releases).

## Contributing

1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D

## Credits

[Dylan DPC](https://github.com/Dylan-DPC)

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
3 changes: 1 addition & 2 deletions src/AuthValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Dpc\HashVerifier;


use Illuminate\Database\Eloquent\Model;

class AuthValidator implements AuthValidatorContract
Expand Down Expand Up @@ -60,4 +59,4 @@ public function validate(array $params) : bool
return $this->validator->verify($params);
}

}
}
3 changes: 1 addition & 2 deletions src/AuthValidatorContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Dpc\HashVerifier;


use Illuminate\Database\Eloquent\Model;

interface AuthValidatorContract
Expand Down Expand Up @@ -35,4 +34,4 @@ public function matches(Model $content, string $nonce) : bool;
* @return bool
*/
public function validate(array $params) : bool;
}
}
3 changes: 1 addition & 2 deletions src/Exceptions/HashFailedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Dpc\HashVerifier\Exceptions;


class HashFailedException extends \Exception
{

Expand All @@ -13,4 +12,4 @@ public function __construct()
{
parent::__construct('Hash Validation Failed');
}
}
}
3 changes: 1 addition & 2 deletions src/Exceptions/NonceFailedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Dpc\HashVerifier\Exceptions;


class NonceFailedException extends \Exception
{

Expand All @@ -13,4 +12,4 @@ public function __construct()
{
parent::__construct('Authentication failed because nonce does not match');
}
}
}
3 changes: 1 addition & 2 deletions src/HMacValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Dpc\HashVerifier;


class HMacValidator implements HMacValidatorContract
{

Expand Down Expand Up @@ -60,4 +59,4 @@ protected function validate(array $params, $hmac) : bool
return hash_equals($hmac, $hash);

}
}
}
3 changes: 1 addition & 2 deletions src/HMacValidatorContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Dpc\HashVerifier;


interface HMacValidatorContract
{
/**
Expand All @@ -13,4 +12,4 @@ interface HMacValidatorContract
* @return bool
*/
public function verify(array $params) : bool;
}
}
3 changes: 1 addition & 2 deletions src/NonceContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Dpc\HashVerifier;


use Illuminate\Database\Eloquent\Model;

interface NonceContract
Expand Down Expand Up @@ -35,4 +34,4 @@ public function store(Model $content, string $nonce) : void;
* @return bool
*/
public function matches(Model $content, string $nonce) : bool;
}
}
Loading