README.md 4.07 KB
Newer Older
1 2 3 4
[![pipeline status](https://gitlab.com/alasdairkeyes/redirecttoken-laravel/badges/master/pipeline.svg)](https://gitlab.com/alasdairkeyes/redirecttoken-laravel/commits/master)
[![coverage report](https://gitlab.com/alasdairkeyes/redirecttoken-laravel/badges/master/coverage.svg)](https://gitlab.com/alasdairkeyes/redirecttoken-laravel/commits/master)
[![Latest Version on Packagist](https://img.shields.io/packagist/v/alasdairkeyes/redirecttoken-laravel.svg)](https://packagist.org/packages/alasdairkeyes/redirecttoken-laravel)
[![Total Downloads](https://img.shields.io/packagist/dt/alasdairkeyes/redirecttoken-laravel.svg)](https://packagist.org/packages/alasdairkeyes/redirecttoken-laravel)
Alasdair Keyes's avatar
Alasdair Keyes committed
5

Alasdair Keyes's avatar
Alasdair Keyes committed
6 7
# redirecttoken-laravel

Alasdair Keyes's avatar
Alasdair Keyes committed
8 9 10 11 12 13 14 15 16 17
Laravel integration for the redirecttoken PHP package

## Description

This package implements the redirecttoken (https://gitlab.com/alasdairkeyes/redirecttoken) for the Laravel framework.

This redirects website visitors to the URI with a 302 redirect. If an invalid request is received a 400 response is returned.

## Installation

18 19 20 21
* Add the package to composer with the following
```
composer require alasdairkeyes/redirecttoken-laravel
```
Alasdair Keyes's avatar
Alasdair Keyes committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

## Configuration

* Publish the config

`php artisan vendor:publish --provider="RedirectToken\Laravel\Providers\RedirectTokenServiceProvider" --tag=config`

* Update your environment with a secret at least 10 characters long. This is a minimum length, the longer the string, the better.

`REDIRECT_TOKEN_SECRET=MyIncrediblySecureSecret`

* If you're using config caching, refresh your cache

`php artisan config:cache`

37 38 39
**If you're using Laravel >=5.5 you can stop here. The rest of the setup will auto-load.**

For Lumen and Laravel <5.5 do the following...
Alasdair Keyes's avatar
Alasdair Keyes committed
40

41
* Add the Service Provider
Alasdair Keyes's avatar
Alasdair Keyes committed
42

43
Add the Class to your `app/config.php` config file
Alasdair Keyes's avatar
Alasdair Keyes committed
44 45

```
46 47 48 49 50 51
'providers' => [
    // Other providers above...
    RedirectToken\Laravel\Providers\RedirectTokenServiceProvider::class,
    // Other providers below...
],
```
Alasdair Keyes's avatar
Alasdair Keyes committed
52

53
* Add the Aliases
Alasdair Keyes's avatar
Alasdair Keyes committed
54

55 56 57 58 59 60 61 62
Add the Alias to your `app/config.php` config file

```
'aliases' => [
        // Other aliases above...
        'RedirectTokenHelper' => RedirectToken\Laravel\Support\RedirectTokenHelper::class,
        // Other aliases below...
    ],
Alasdair Keyes's avatar
Alasdair Keyes committed
63 64
```

65

Alasdair Keyes's avatar
Alasdair Keyes committed
66 67 68 69 70 71
## Example

In your template just add the following directive into your `href` value

`<a href="@redirectUrl('https://www.somewebsite.com')">Redirect To Some Website</a>`

Alasdair Keyes's avatar
Alasdair Keyes committed
72 73 74 75
Or you can also use a variable

`<a href="@redirectUrl($websiteToRedirectTo)">Redirect To Some Website</a>`

Alasdair Keyes's avatar
Alasdair Keyes committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129

## Extending functionality

The following settings can be updated by updating your `.env` file

### Forwarding Path

By default the forwarding path in your application is `/fwd`. This can be changed by using the following

`REDIRECT_TOKEN_PATH=/forwarder`

### Hashing Algorithm

This uses the `sha256` hashing algorithm to generate the token. This can be changed with

`REDIRECT_TOKEN_HASH_ALGO=sha512`

### Query keys

The default query string generated uses the query parameters `uri` and `token`

This can be changed with

`REDIRECT_TOKEN_URI_QUERY_KEY=redirectto`

`REDIRECT_TOKEN_TOKEN_QUERY_KEY=checksum`

### Custom error page

You can customize the page returned when an invalid redirect request is received by creating a `resources/views/errors/400.blade.php`

### Events

The following events are used

* When a valid redirect is received - `RedirectToken\Laravel\Event\ValidRedirectRequest`
* When an invalid redirect is received `RedirectToken\Laravel\Event\InvalidRedirectRequest`

You can listen and handle these events by adding the following to the `$listen` variable in `app/Providers/EventServiceProvider.php`

```
protected $listen = [
	'RedirectToken\Laravel\Event\ValidRedirectRequest' => [
		'App\Listeners\ValidRedirect',
	]
];
```

Some example listeners are included and can be added to your app with the following command

`php artisan vendor:publish --provider="RedirectToken\Laravel\Providers\RedirectTokenServiceProvider" --tag=listeners`

## Site

Alasdair Keyes's avatar
Alasdair Keyes committed
130
https://gitlab.com/alasdairkeyes/redirecttoken-laravel
Alasdair Keyes's avatar
Alasdair Keyes committed
131 132 133 134 135 136 137 138 139 140


## Author

* Alasdair Keyes - https://akeyes.co.uk/


## License

Released under GPL V3 - See included license file.