You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+73-79Lines changed: 73 additions & 79 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,35 +34,74 @@ When using Composer run the following command:
34
34
$ composer require securenative/securenative-php
35
35
```
36
36
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
42
38
```php
43
39
require_once __DIR__ . '/vendor/autoload.php';
44
40
45
41
use SecureNative\sdk\SecureNative;
46
42
use SecureNative\sdk\SecureNativeOptions;
43
+
use SecureNative\sdk\EventTypes;
44
+
use SecureNative\sdk\SecureNativeContext;
45
+
```
47
46
48
-
$options = new SecureNativeOptions();
47
+
## Initialize the SDK
49
48
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:
52
50
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);
54
64
```
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).
59
83
```php
60
-
require_once __DIR__ . '/vendor/autoload.php';
84
+
SecureNative::init();
85
+
```
61
86
62
-
use SecureNative\sdk\SecureNative;
87
+
### Option 3: Initialize via environment variables
63
88
89
+
Pass desired environment variables (for example):
64
90
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();
66
105
```
67
106
68
107
## Tracking events
@@ -71,20 +110,14 @@ Once the SDK has been initialized, tracking requests sent through the SDK
71
110
instance.
72
111
73
112
```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;
75
120
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
88
121
$ctx = new SecureNativeContext($clientToken, $ip, $remoteIp, $headers, $url, $method, $body);
89
122
90
123
SecureNative::track(array(
@@ -104,14 +137,8 @@ SecureNative::track(array(
104
137
));
105
138
```
106
139
140
+
You can also create request context from request:
107
141
```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
-
115
142
SecureNative::track(array(
116
143
'event' => EventTypes::LOG_IN,
117
144
'context' => SecureNative::contextFromContext(),
@@ -129,64 +156,31 @@ SecureNative::track(array(
129
156
));
130
157
```
131
158
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
-
153
159
## Verify events
154
160
155
161
**Example**
156
162
157
163
```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
-
165
164
$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
+
]
173
172
));
174
173
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"])
178
177
```
179
178
180
179
## Webhook signature verification
181
180
182
181
Apply our filter to verify the request is from us, for example:
0 commit comments