Skip to content

Commit dfd5a05

Browse files
committed
SN-1913 Align readme.md
1 parent 4b3d5fd commit dfd5a05

1 file changed

Lines changed: 73 additions & 79 deletions

File tree

README.md

Lines changed: 73 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -34,35 +34,74 @@ When using Composer run the following command:
3434
$ composer require securenative/securenative-php
3535
```
3636

37-
## Initialize the SDK
38-
39-
To get your *API KEY*, login to your SecureNative account and go to project settings page:
40-
41-
### Option 1: Initialize via ConfigurationBuilder
37+
### Add required imports
4238
```php
4339
require_once __DIR__ . '/vendor/autoload.php';
4440

4541
use SecureNative\sdk\SecureNative;
4642
use SecureNative\sdk\SecureNativeOptions;
43+
use SecureNative\sdk\EventTypes;
44+
use SecureNative\sdk\SecureNativeContext;
45+
```
4746

48-
$options = new SecureNativeOptions();
47+
## Initialize the SDK
4948

50-
$options->setMaxEvents(10);
51-
$options->setLogLevel("error");
49+
To get your *API KEY*, login to your SecureNative account and go to project settings page:
5250

53-
SecureNative::init("YOUR_API_KEY", $options);
51+
### Option 1: Initialize via API_KEY and SecureNativeOptions
52+
```php
53+
$options = new SecureNativeOptions();
54+
$options->setTimeout(100)
55+
->setApiUrl("API URL")
56+
->setDisable(false)
57+
->setInterval(100)
58+
->setAutoSend(true)
59+
->setMaxEvents(10)
60+
->setLogLevel('fatal');
61+
62+
// Passing `$options` is optional, will use default params
63+
SecureNative::init("[API_KEY]", $options);
5464
```
55-
### Option 2: Initialize via API Key
56-
57-
Initialize using default options.
58-
65+
### Option 2: Initialize via configuration file
66+
67+
Attach `securenative.json` file to your root folder:
68+
69+
```json
70+
{
71+
"SECURENATIVE_API_KEY": "SOME_API_KEY",
72+
"SECURENATIVE_APP_NAME": "SOME_APP_NAME",
73+
"SECURENATIVE_API_URL": "SOME_API_URL",
74+
"SECURENATIVE_INTERVAL": 1000,
75+
"SECURENATIVE_MAX_EVENTS": 100,
76+
"SECURENATIVE_TIMEOUT": 1500,
77+
"SECURENATIVE_AUTO_SEND": true,
78+
"SECURENATIVE_DISABLE": false,
79+
"SECURENATIVE_LOG_LEVEL": "fatal"
80+
}
81+
```
82+
Then, call SDK's `init` function without props (sending props will override JSON configurations).
5983
```php
60-
require_once __DIR__ . '/vendor/autoload.php';
84+
SecureNative::init();
85+
```
6186

62-
use SecureNative\sdk\SecureNative;
87+
### Option 3: Initialize via environment variables
6388

89+
Pass desired environment variables (for example):
6490

65-
SecureNative::init("YOUR_API_KEY");
91+
```shell script
92+
SECURENATIVE_API_KEY=TEST_KEY
93+
SECURENATIVE_API_URL=http://url
94+
SECURENATIVE_INTERVAL=100
95+
SECURENATIVE_MAX_EVENTS=30
96+
SECURENATIVE_TIMEOUT=1500
97+
SECURENATIVE_AUTO_SEND=true
98+
SECURENATIVE_DISABLE=false
99+
SECURENATIVE_LOG_LEVEL=fatal
100+
```
101+
102+
Then, call SDK's `init` function without props (sending props will override JSON configurations).
103+
```php
104+
SecureNative::init();
66105
```
67106

68107
## Tracking events
@@ -71,20 +110,14 @@ Once the SDK has been initialized, tracking requests sent through the SDK
71110
instance.
72111

73112
```php
74-
require_once __DIR__ . '/vendor/autoload.php';
113+
$clientToken = "[SECURED_CLIENT_TOKEN]";
114+
$headers = (object)["user-agent" => "Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us"];
115+
$ip = "79.179.88.157";
116+
$remoteIp = null;
117+
$url = null;
118+
$method = null;
119+
$body = null;
75120

76-
use SecureNative\sdk\SecureNative;
77-
use SecureNative\sdk\SecureNativeOptions;
78-
use SecureNative\sdk\EventTypes;
79-
use SecureNative\sdk\SecureNativeContext;
80-
81-
$clientToken = "SECURED_CLIENT_TOKEN"
82-
$headers = (object)["user-agent" => "Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us"] // User-Agent header is important to get device information!
83-
$ip = "127.0.0.1"
84-
$remoteIp = "127.0.0.1"
85-
$url = null
86-
$method = null
87-
$body = null
88121
$ctx = new SecureNativeContext($clientToken, $ip, $remoteIp, $headers, $url, $method, $body);
89122

90123
SecureNative::track(array(
@@ -104,14 +137,8 @@ SecureNative::track(array(
104137
));
105138
```
106139

140+
You can also create request context from request:
107141
```php
108-
require_once __DIR__ . '/vendor/autoload.php';
109-
110-
use SecureNative\sdk\SecureNative;
111-
use SecureNative\sdk\EventTypes;
112-
use SecureNative\sdk\SecureNativeContext;
113-
114-
115142
SecureNative::track(array(
116143
'event' => EventTypes::LOG_IN,
117144
'context' => SecureNative::contextFromContext(),
@@ -129,64 +156,31 @@ SecureNative::track(array(
129156
));
130157
```
131158

132-
You can also create request context from request:
133-
134-
```php
135-
require_once __DIR__ . '/vendor/autoload.php';
136-
137-
use SecureNative\sdk\SecureNative;
138-
use SecureNative\sdk\EventTypes;
139-
use SecureNative\sdk\SecureNativeContext;
140-
141-
142-
SecureNative::track(array(
143-
'event' => EventTypes::LOG_IN,
144-
'context' => SecureNativeContext::fromRequest(),
145-
'userId' => '1234',
146-
'userTraits' => (object)[
147-
'name' => 'Your Name',
148-
'email' => 'name@gmail.com'
149-
],
150-
));
151-
```
152-
153159
## Verify events
154160

155161
**Example**
156162

157163
```php
158-
require_once __DIR__ . '/vendor/autoload.php';
159-
160-
use SecureNative\sdk\SecureNative;
161-
use SecureNative\sdk\EventTypes;
162-
use SecureNative\sdk\SecureNativeContext;
163-
164-
165164
$ver = SecureNative::verify(array(
166-
'event' => EventTypes::VERIFY,
167-
'userId' => '1234',
168-
'context' => SecureNativeContext::fromRequest(),
169-
'userTraits' => (object)[
170-
'name' => 'Your Name',
171-
'email' => 'name@gmail.com'
172-
]
165+
'event' => EventTypes::VERIFY,
166+
'userId' => '1234',
167+
'context' => SecureNativeContext::fromRequest(),
168+
'userTraits' => (object)[
169+
'name' => 'Your Name',
170+
'email' => 'name@gmail.com'
171+
]
173172
));
174173

175-
$ver.riskLevel // Low, Medium, High
176-
$ver.score // Risk score: 0 - 1 (0 - Very Low, 1 - Very High)
177-
$ver.triggers // ["TOR", "New IP", "New City"]
174+
print_r($ver->riskLevel); // (Low, Medium, High)
175+
print_r($ver->score); // (0 - Very Low, 1 - Very High)
176+
print_r($ver->triggers); // (Example: ["TOR", "New IP", "New City"])
178177
```
179178

180179
## Webhook signature verification
181180

182181
Apply our filter to verify the request is from us, for example:
183182

184183
```php
185-
require_once __DIR__ . '/vendor/autoload.php';
186-
187-
use SecureNative\sdk\SecureNative;
188-
189-
190184
$verified = SecureNative::getMiddleware()->verifySignature();
191185

192186
if ($verified) {

0 commit comments

Comments
 (0)