Skip to content

Commit 2724f3b

Browse files
committed
add docs
1 parent 92b6372 commit 2724f3b

File tree

12 files changed

+386
-0
lines changed

12 files changed

+386
-0
lines changed

docs/assets/favicon.ico

14.7 KB
Binary file not shown.

docs/assets/flame.svg

Lines changed: 11 additions & 0 deletions
Loading

docs/assets/github-dark-dimmed.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}/*!
2+
Theme: GitHub Dark Dimmed
3+
Description: Dark dimmed theme as seen on github.com
4+
Author: github.com
5+
Maintainer: @Hirse
6+
Updated: 2021-05-15
7+
Modified: 2022:12:27 by @michalsn
8+
9+
Colors taken from GitHub's CSS
10+
*/.hljs{color:#adbac7 !important;background-color:#22272e !important}.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-template-tag,.hljs-template-variable,.hljs-type,.hljs-variable.language_{color:#f47067}.hljs-title,.hljs-title.class_,.hljs-title.class_.inherited__,.hljs-title.function_{color:#dcbdfb}.hljs-attr,.hljs-attribute,.hljs-literal,.hljs-meta,.hljs-number,.hljs-operator,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-id,.hljs-variable{color:#6cb6ff}.hljs-meta .hljs-string,.hljs-regexp,.hljs-string{color:#96d0ff}.hljs-built_in,.hljs-symbol{color:#f69d50}.hljs-code,.hljs-comment,.hljs-formula{color:#768390}.hljs-name,.hljs-quote,.hljs-selector-pseudo,.hljs-selector-tag{color:#8ddb8c}.hljs-subst{color:#adbac7}.hljs-section{color:#316dca;font-weight:700}.hljs-bullet{color:#eac55f}.hljs-emphasis{color:#adbac7;font-style:italic}.hljs-strong{color:#adbac7;font-weight:700}.hljs-addition{color:#b4f1b4;background-color:#1b4721}.hljs-deletion{color:#ffd8d3;background-color:#78191b}
11+
12+
[data-md-color-scheme="default"] {
13+
--md-default-fg-color--lightest: #575757;
14+
--md-default-fg-color--light: #959595;
15+
}

docs/assets/hljs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
document.addEventListener('DOMContentLoaded', (ev) => {
2+
hljs.highlightAll();
3+
});

docs/commands.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Commands
2+
3+
Available options:
4+
5+
- [publish](#publish)
6+
- [algorithms](#algorithms)
7+
8+
### publish
9+
10+
This command will publish configuration file to the APP namespace.
11+
12+
```console
13+
php spark signedurl:publish
14+
```
15+
16+
### algorithms
17+
18+
This command will list all avaliable algorithms options to use with `$algorithm` config variable.`.
19+
20+
```console
21+
php spark signedurl:algorithms
22+
```
23+
24+
!!! warning
25+
26+
If you're not sure what you're doing please stay with the default option.

docs/configuration.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Configuration
2+
3+
To make changes to the config file, we have to have our copy in the `app/Config/SignedUrl.php`. Luckily, this package comes with handy command that will make this easy.
4+
5+
When we run:
6+
7+
php spark signedurl:publish
8+
9+
We will get our copy ready for modifications.
10+
11+
---
12+
13+
Available options:
14+
15+
- [$expirationTime](#expirationTime)
16+
- [$algorithm](#algorithm)
17+
- [$expirationKey](#expirationKey)
18+
- [$signatureKey](#signatureKey)
19+
- [$algorithmKey](#algorithmKey)
20+
- [$includeAlgorithmKey](#includeAlgorithmKey)
21+
- [$redirect](#redirect)
22+
- [$show404](#show404)
23+
24+
### $expirationTime
25+
26+
This setting allows us to set a fixed time after which the signed URL will expire.
27+
It's number of seconds in unix timestamp that will be added to the current date.
28+
29+
By default, this is set to `null`.
30+
31+
### $algorithm
32+
33+
This setting allows us to set algorithm that will be used during signing the URLs.
34+
35+
You can see the list of all available options when running command:
36+
37+
php spark signedurl:algorithms
38+
39+
!!! warning
40+
41+
When you don't include used algorithm to the query string (default), then changing algorithm will result with invalidating all the generated URLs.
42+
43+
### $expirationKey
44+
45+
This is the name of the query string key, which will be responsible for storing the time after which the URL will expire.
46+
47+
By default, this is set to `expires`.
48+
49+
!!! note
50+
51+
Whatever name you will choose, treat it as a restricted name and don't use it as a part of the query string in your code.
52+
53+
### $signatureKey
54+
55+
This is the name of the query string key, which will be responsible for storing the signature by which the validity of the entire URL will be checked.
56+
57+
By default, this is set to `signature`.
58+
59+
!!! note
60+
61+
Whatever name you will choose, treat it as a restricted name and don't use it as a part of the query string in your code.
62+
63+
### $algorithmKey
64+
65+
This is the name of the query string key, which will be responsible for storing the algorithm by which the validity of the entire URL will be checked.
66+
67+
By default, this is set to `algorithm`.
68+
69+
!!! note
70+
71+
Whatever name you will choose, treat it as a restricted name and don't use it as a part of the query string in your code.
72+
73+
### $includeAlgorithmKey
74+
75+
This setting determines if the algorithm will be included to the query string of the generated URL.
76+
77+
By default, this is set to `false`.
78+
79+
### $redirect
80+
81+
This setting is used in the Filter to determine whether we will redirect user to the previous page with the `error`, when URL will not be valid or expired.
82+
83+
By default, this is set to `false`.
84+
85+
### $show404
86+
87+
This setting is used in the Filter to determine whether we will show a 404 page, when URL will not be valid or expired.
88+
89+
By default, this is set to `false`.

docs/filters.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Filters
2+
3+
## Overview
4+
5+
To validate signed URLs we can use build in filter. We can enable it in two simple steps.
6+
7+
1. We have to add our filter to the `$aliases` array.
8+
2. And then define when filter should be fired up. In the example below we will assume it will be used when the first segment of the url will contain `signed-urls` string.
9+
10+
```php
11+
// app/Config/Filters.php
12+
<?php
13+
14+
...
15+
16+
use Michalsn\CodeIgniterSignedUrl\Filters\SignedUrl;
17+
18+
class Filters extends BaseConfig
19+
{
20+
...
21+
22+
public $aliases = [
23+
...
24+
'signedurl' => SignedUrl::class
25+
];
26+
27+
...
28+
29+
public $filters = [
30+
'signedurl' => ['before' => ['signed-urls/*']],
31+
];
32+
}
33+
```
34+
35+
## Options
36+
37+
By default, this filter will throw `SignedUrlException` when the URL won't be signed or will be expired. But there are other options, and we can enable them by editing the config file:
38+
39+
* We can redirect to the previous page
40+
* Or show 404 page
41+
42+
More info you can find in the Config section.
43+
44+
!!! note
45+
46+
Remember, that if the filter implementation doesn't suit you, you can always create your own, which will behave differently upon an error. You can also not use the filter at all and make the check in the controller.

docs/helpers.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Helpers
2+
3+
Available options:
4+
5+
- [signedurl()](#signedurl)
6+
7+
#### signedurl()
8+
9+
This function returns the `SignedUrl` class instance.
10+
11+
```php
12+
signedurl()->setExpiration(DAY)->siteUrl('controller/method');
13+
```

docs/index.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# CodeIgniter Signed URL Documentation
2+
3+
This library makes it easy to sign URLs in CodeIgniter 4 framework. It can be used to **prevent manual URL manipulation** or to **auto expiry links** that have been given to the end user.
4+
5+
## Overview
6+
7+
We can sign URLs very easy with two main methods that act similar to the helper functions known from CodeIgniter's URL helper.
8+
9+
```php
10+
echo signedurl()->siteUrl('controller/method?query=string');
11+
// https://example.com/controller/method?query=string&signature=signature-goes-here
12+
```
13+
14+
```php
15+
echo signedurl()->setExpiration(DAY * 2)->urlTo('namedRoute', 12);
16+
// https://example.com/route/name/12?expiration=1671980371&signature=signature-goes-here
17+
```
18+

docs/installation.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Installation
2+
3+
- [Composer Installation](#composer-installation)
4+
- [Manual Installation](#manual-installation)
5+
- [Generate encryption key](#generate-encryption-key)
6+
7+
## Composer Installation
8+
9+
The only thing you have to do is to run this command, and you're ready to go.
10+
11+
```console
12+
composer require michalsn/codeigniter-signed-url
13+
```
14+
15+
## Manual Installation
16+
17+
In the example below we will assume, that files from this project will be located in `app/ThirdParty/signed-url` directory.
18+
19+
Download this project and then enable it by editing the `app/Config/Autoload.php` file and adding the `Michalsn\CodeIgniterSignedUrl` namespace to the `$psr4` array. You also have to add `Common.php` to the `$files` array, like in the below example:
20+
21+
```php
22+
<?php
23+
24+
...
25+
26+
public $psr4 = [
27+
APP_NAMESPACE => APPPATH, // For custom app namespace
28+
'Config' => APPPATH . 'Config',
29+
'Michalsn\CodeIgniterSignedUrl' => APPPATH . 'ThirdParty/signed-url/src',
30+
];
31+
32+
...
33+
34+
public $files = [
35+
APPPATH . 'ThirdParty/signed-url/src/Common.php',
36+
];
37+
```
38+
39+
## Generate encryption key
40+
41+
Make sure that you have generated the encryption key. If not, please run command:
42+
43+
```console
44+
php spark generate:key
45+
```
46+
47+
!!! warning
48+
49+
Please remember that any change made to the `encryption key` after generating signed URLs will auto expire them.
50+
51+

0 commit comments

Comments
 (0)