Skip to content

Commit

Permalink
Add .gitattributes
Browse files Browse the repository at this point in the history
Spelling and grammar fixes for Readme.md
Composer.json is ready for prod
  • Loading branch information
alexeygeno committed Aug 8, 2023
1 parent f0d62b3 commit 26b7942
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 49 deletions.
6 changes: 6 additions & 0 deletions .gitatttributes
@@ -0,0 +1,6 @@
.github export-ignore
tests export-ignore
phpunit.xml export-ignore
.gitattributes export-ignore
.gitignore export-ignore
phpstan.neon.dist export-ignore
72 changes: 34 additions & 38 deletions README.md
@@ -1,32 +1,37 @@
# Phone Verification Laravel #
# Phone Verification via [Laravel Notification Channels](https://laravel-notification-channels.com/)

The usual way to sign in/sign up on a modern website or mobile app is:
- A user initiates verification submitting a phone number
- The user receives an sms or a call with an [ otp](https://en.wikipedia.org/wiki/One-time_password)
- The user completes verification submitting the [ otp](https://en.wikipedia.org/wiki/One-time_password)
[![Build Status](https://github.com/alexeygeno/phone-verification-laravel/workflows/tests/badge.svg)](https://github.com/alexeygeno/phone-verification-laravel/actions)
[![Build Status](https://github.com/alexeygeno/phone-verification-laravel/workflows/pint/badge.svg)](https://github.com/alexeygeno/phone-verification-php/actions)
[![Coverage Status](https://coveralls.io/repos/github/alexeygeno/phone-verification-laravel/badge.svg)](https://coveralls.io/github/alexeygeno/phone-verification-laravel)

This library is built on top of [ alexeygeno/phone-verification-php ](https://github.com/alexeygeno/phone-verification-php) allows to set this up.

Among supported features:
- Easy(.env) switching between different storages and notification channels
- Configurable length and expiration time for OTP
Signing in or signing up on a modern website or mobile app typically follows these steps:
- A user initiates verification by submitting a phone number
- The user receives an SMS or a call with a one-time password [(OTP)](https://en.wikipedia.org/wiki/One-time_password)
- The user completes verification by submitting the [OTP](https://en.wikipedia.org/wiki/One-time_password)

This library is built on top of [ alexeygeno/phone-verification-php ](https://github.com/alexeygeno/phone-verification-php) and allows to set this up

Supported features:
- Easy(**.env**) switching between different storages and notification channels
- Configurable length and expiration time for [OTP](https://en.wikipedia.org/wiki/One-time_password)
- Configurable rate limits
- Localization
- Logging notifications instead of sending the real ones. Useful for non-production environments
- Usage with different Laravel approaches: [ Automatic injection ](https://laravel.com/docs/10.x/container#automatic-injection), [ facade ](https://laravel.com/docs/10.x/facades), [ commands ](https://laravel.com/docs/10.x/artisan#writing-commands)
- Routes out of the box for the quick start
- Usage with different Laravel approaches: [automatic injection](https://laravel.com/docs/9.x/container#automatic-injection), [facade](https://laravel.com/docs/9.x/facades), and [commands](https://laravel.com/docs/9.x/artisan#writing-commands)
- Logging notifications instead of sending real ones, beneficial for non-production environments
- Out-of-the-box routes for quick start

## Requirements
Laravel 9.x
[Laravel 9.x](https://laravel.com/docs/9.x)

One of the Laravel notification channels: [ vonage ](https://github.com/laravel/vonage-notification-channel), [ twilio ](https://github.com/laravel-notification-channels/twilio), [ messagebird ](https://github.com/laravel-notification-channels/messagebird) and [many more ](https://github.com/laravel-notification-channels?q=&type=all&language=php&sort=)
One of Laravel notification channels: [vonage](https://github.com/laravel/vonage-notification-channel), [twilio](https://github.com/laravel-notification-channels/twilio), [messagebird](https://github.com/laravel-notification-channels/messagebird) and [many more ](https://github.com/laravel-notification-channels?q=&type=all&language=php&sort=)

One of the supported storages: [ predis/predis ](https://github.com/predis/predis), [ jenssegers/laravel-mongodb ](https://github.com/jenssegers/laravel-mongodb)
One of the supported storages: [predis/predis](https://github.com/predis/predis), [jenssegers/laravel-mongodb](https://github.com/jenssegers/laravel-mongodb)
## Installation
```shell
composer require alexgeno/phone-verification-laravel predis/predis laravel/vonage-notification-channel
```
**Note:** redis as a storage and vonage as a notification channel are defaults in config
**Note:** Redis as a storage and Vonage as a notification channel are defaults in the configuration

## Usage
#### Automatic injection
Expand All @@ -44,14 +49,10 @@ public function complete(\AlexGeno\PhoneVerification\Manager\Completer $manager)
```
#### Facade
```php
use \AlexGeno\PhoneVerificationLaravel\Facades\PhoneVerification;

PhoneVerification::initiate('+15417543010');
\AlexGeno\PhoneVerificationLaravel\Facades\PhoneVerification::initiate('+15417543010');
```
```php
use \AlexGeno\PhoneVerificationLaravel\Facades\PhoneVerification;

PhoneVerification::complete('+15417543010', 1234);
\AlexGeno\PhoneVerificationLaravel\Facades\PhoneVerification::complete('+15417543010', 1234);
```
#### Commands
```shell
Expand All @@ -62,38 +63,35 @@ php artisan phone-verification:complete --to=+15417543010 --otp=1234
```
#### Routes
```shell
curl -d "to=+380935259282" http://localhost/phone-verification/initiate
curl -d "to=+380935259282" localhost/phone-verification/initiate
#{"ok":true,"message":"Sms has been sent. Check your Phone!"}
```
```shell
curl -d "to=+380935259282&otp=1234" http://localhost/phone-verification/complete
curl -d "to=+380935259282&otp=1234" localhost/phone-verification/complete
#{"ok":true,"message":"The verification is done!"}
```
**Note**: The package routes are available by default. To make them unavailable without redefining the service provider just change the bool key **phone-verification.sender.to_log** in config
**Note**: The package routes are available by default. To make them unavailable without redefining the service provider, change the bool key **phone-verification.sender.to_log** in the configuration

## Different storages and notification channels
To switch between [ available ](#Requirements) storages and notifications channels you need only to install the respective package and change .env.
To switch between [available](#requirements) storages and notifications channels, install the respective package and update the **.env** file

For instance if you need **mongodb** as a storage and **twilio** as a notification channel just do this:
For example, to use **Mongodb** as a storage and **Twilio** as a notification channel:
```shell
composer require jenssegers/laravel-mongodb laravel-notification-channels/twilio
```
```dotenv
PHONE_VERIFICATION_SENDER=twilio
PHONE_VERIFICATION_STORAGE=mongodb
```
If what's available is not enough you can redefine the service provider and add a storage (implementing *\AlexGeno\PhoneVerification\Storage\I*) or/and a sender (implementing \AlexGeno\PhoneVerification\Sender\I)



If the available options are not sufficient, you can redefine the service provider and add a custom storage (implementing **\AlexGeno\PhoneVerification\Storage\I**) or/and a sender (implementing **\AlexGeno\PhoneVerification\Sender\I**)
## Configuration
```php
[
'storage' => [
'driver' => env('PHONE_VERIFICATION_STORAGE', 'redis'), // redis || mongodb
'redis' => [
'connection' => 'default',
// keys settings - normally you don't need to change it
// the key settings - normally you don't need to change them
'settings' => [
'prefix' => 'pv:1',
'session_key' => 'session',
Expand All @@ -102,7 +100,7 @@ If what's available is not enough you can redefine the service provider and add
],
'mongodb' => [
'connection' => 'mongodb',
// collections settings - normally you don't need to change it
// the collection settings - normally you don't need to change them
'settings' => [
'collection_session' => 'session',
'collection_session_counter' => 'session_counter',
Expand All @@ -122,17 +120,15 @@ If what's available is not enough you can redefine the service provider and add
'period_secs' => 86400,
'count' => 10,
],
'complete' => [ // for every 'to' no more than 5 failed completion over 5 minutes
'period_secs' => 300, // this is also the expiration period for an otp
'complete' => [ // for every 'to' no more than 5 failed completions over 5 minutes
'period_secs' => 300, // this is also the expiration period for OTP
'count' => 5,
],
],
],
];

```


## Publishing
#### Config
```shell
Expand All @@ -146,7 +142,7 @@ php artisan vendor:publish --tag=phone-verification-lang
```shell
php artisan vendor:publish --tag=phone-verification-migrations
```
**Note**: Only the mongodb storage driver needs migrations
**Note**: Only the **MongoDB** storage driver requires migrations



36 changes: 27 additions & 9 deletions composer.json
@@ -1,8 +1,21 @@
{
"name": "alexgeno/phone-verification-laravel",
"description":"An extensible and configurable php library to verify a phone",
"description":"A Laravel library to verify a phone via notification channels. Any notification channel can be used as a sender. Redis(predis) or MongoDb can be used a storage.",
"type": "library",
"keywords":["otp","phone", "verification", "verify", "sms", "call", "2fa", "2factor","authentication", "signin",
"signup", "redis", "mongo", "mongodb", "verify-by-phone", "otp", "notification", "notification-channel",
"twilio", "messagebird", "vonage", "touch-sms", "clickatell", "jusibe", "smsc-ru", "authy", "cmsms", "46elks",
"sipgate", "all-my-sms", "smspoh", "turbosms", "vodafone", "africastalking", "sms77", "smsapi", "sms-broadcast"
],
"license": "MIT",
"authors": [
{
"name": "Alexey Geno",
"email": "alexeygeno@gmail.com",
"homepage":"https://github.com/alexeygeno"
}
],
"homepage": "https://github.com/alexeygeno/phone-verification-laravel",
"autoload": {
"psr-4": {
"AlexGeno\\PhoneVerificationLaravel\\": "src/"
Expand All @@ -20,17 +33,17 @@
]
}
},
"authors": [
{
"name": "Alexey Geno",
"email": "alexeygeno@gmail.com",
"homepage":"https://github.com/alexeygeno"
}
],
"require": {
"php":"^8.0",
"alexgeno/phone-verification": "^1.0"
},
"suggest": {
"predis/predis": "required to use Redis as a storage",
"enssegers/mongodb": "required to use MongoDB as a storage",
"laravel-notification-channels/messagebird": "required to use Messagebird as a sender's notification channel",
"laravel-notification-channels/twilio": "required to use Twilio as a sender's notification channel",
"laravel/vonage-notification-channel": "required to use Vonage as a sender's notification channel"
},
"require-dev": {
"jenssegers/mongodb": "^3.9",
"predis/predis": "^2.2",
Expand All @@ -43,5 +56,10 @@
"nunomaduro/collision": "^6.2",
"laravel/pint": "^1.5",
"phpstan/phpstan": "^1.10"
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
4 changes: 2 additions & 2 deletions config/phone-verification.php
Expand Up @@ -34,8 +34,8 @@
'period_secs' => 86400,
'count' => 10,
],
'complete' => [ // for every 'to' no more than 5 failed completion over 5 minutes
'period_secs' => 300, // this is also the expiration period for otp
'complete' => [ // for every 'to' no more than 5 failed completions over 5 minutes
'period_secs' => 300, // this is also the expiration period for OTP
'count' => 5,
],
],
Expand Down

0 comments on commit 26b7942

Please sign in to comment.