-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.html
More file actions
1044 lines (968 loc) · 37.3 KB
/
README.html
File metadata and controls
1044 lines (968 loc) · 37.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>README</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
/* RESET
=============================================================================*/
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
}
/* BODY
=============================================================================*/
body {
font-family: Helvetica, arial, freesans, clean, sans-serif;
font-size: 14px;
line-height: 1.6;
color: #333;
background-color: #fff;
padding: 20px;
max-width: 960px;
margin: 0 auto;
}
body > *:first-child {
margin-top: 0 !important;
}
body > *:last-child {
margin-bottom: 0 !important;
}
/* BLOCKS
=============================================================================*/
p, blockquote, ul, ol, dl, table, pre {
margin: 15px 0;
}
/* HEADERS
=============================================================================*/
h1, h2, h3, h4, h5, h6 {
margin: 20px 0 10px;
padding: 0;
font-weight: bold;
-webkit-font-smoothing: antialiased;
}
h1 tt, h1 code, h2 tt, h2 code, h3 tt, h3 code, h4 tt, h4 code, h5 tt, h5 code, h6 tt, h6 code {
font-size: inherit;
}
h1 {
font-size: 28px;
color: #000;
}
h2 {
font-size: 24px;
border-bottom: 1px solid #ccc;
color: #000;
}
h3 {
font-size: 18px;
}
h4 {
font-size: 16px;
}
h5 {
font-size: 14px;
}
h6 {
color: #777;
font-size: 14px;
}
body > h2:first-child, body > h1:first-child, body > h1:first-child + h2, body > h3:first-child, body > h4:first-child, body > h5:first-child, body > h6:first-child {
margin-top: 0;
padding-top: 0;
}
a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
margin-top: 0;
padding-top: 0;
}
h1 + p, h2 + p, h3 + p, h4 + p, h5 + p, h6 + p {
margin-top: 10px;
}
/* LINKS
=============================================================================*/
a {
color: #4183C4;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
/* LISTS
=============================================================================*/
ul, ol {
padding-left: 30px;
}
ul li > :first-child,
ol li > :first-child,
ul li ul:first-of-type,
ol li ol:first-of-type,
ul li ol:first-of-type,
ol li ul:first-of-type {
margin-top: 0px;
}
ul ul, ul ol, ol ol, ol ul {
margin-bottom: 0;
}
dl {
padding: 0;
}
dl dt {
font-size: 14px;
font-weight: bold;
font-style: italic;
padding: 0;
margin: 15px 0 5px;
}
dl dt:first-child {
padding: 0;
}
dl dt > :first-child {
margin-top: 0px;
}
dl dt > :last-child {
margin-bottom: 0px;
}
dl dd {
margin: 0 0 15px;
padding: 0 15px;
}
dl dd > :first-child {
margin-top: 0px;
}
dl dd > :last-child {
margin-bottom: 0px;
}
/* CODE
=============================================================================*/
pre, code, tt {
font-size: 12px;
font-family: Consolas, "Liberation Mono", Courier, monospace;
}
code, tt {
margin: 0 0px;
padding: 0px 0px;
white-space: nowrap;
border: 1px solid #eaeaea;
background-color: #f8f8f8;
border-radius: 3px;
}
pre > code {
margin: 0;
padding: 0;
white-space: pre;
border: none;
background: transparent;
}
pre {
background-color: #f8f8f8;
border: 1px solid #ccc;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px;
}
pre code, pre tt {
background-color: transparent;
border: none;
}
kbd {
-moz-border-bottom-colors: none;
-moz-border-left-colors: none;
-moz-border-right-colors: none;
-moz-border-top-colors: none;
background-color: #DDDDDD;
background-image: linear-gradient(#F1F1F1, #DDDDDD);
background-repeat: repeat-x;
border-color: #DDDDDD #CCCCCC #CCCCCC #DDDDDD;
border-image: none;
border-radius: 2px 2px 2px 2px;
border-style: solid;
border-width: 1px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
line-height: 10px;
padding: 1px 4px;
}
/* QUOTES
=============================================================================*/
blockquote {
border-left: 4px solid #DDD;
padding: 0 15px;
color: #777;
}
blockquote > :first-child {
margin-top: 0px;
}
blockquote > :last-child {
margin-bottom: 0px;
}
/* HORIZONTAL RULES
=============================================================================*/
hr {
clear: both;
margin: 15px 0;
height: 0px;
overflow: hidden;
border: none;
background: transparent;
border-bottom: 4px solid #ddd;
padding: 0;
}
/* TABLES
=============================================================================*/
table th {
font-weight: bold;
}
table th, table td {
border: 1px solid #ccc;
padding: 6px 13px;
}
table tr {
border-top: 1px solid #ccc;
background-color: #fff;
}
table tr:nth-child(2n) {
background-color: #f8f8f8;
}
/* IMAGES
=============================================================================*/
img {
max-width: 100%
}
</style>
</head>
<body>
<h1 id="rublon-php-sdk">Rublon PHP SDK</h1>
<h2 id="table-of-contents">Table of Contents</h2>
<ol type="1">
<li><a href="#overview">Overview</a></li>
<li><a href="#use-cases">Use Cases</a></li>
<li><a href="#auth-methods">Supported Authentication Methods</a></li>
<li><a href="#before-start">Before You Start</a>
<ul>
<li><a href="#create-app">Create an Application in the Rublon Admin Console</a></li>
<li><a href="#install-ra">Optional: Install Rublon Authenticator</a></li>
</ul>
</li>
<li><a href="#config">Configuration</a>
<ul>
<li><a href="#init-assumptions">INFO: Initial Assumptions</a></li>
<li><a href="#modifying-library">INFO: Modifying the Library</a></li>
<li><a href="#init-library">Initialize the Library</a></li>
<li><a href="#perform-auth">Perform Authentication</a></li>
<li><a href="#verify-conf">Verify Configuration</a></li>
<li><a href="#final-auth">Finalize Authentication</a></li>
</ul>
</li>
<li><a href="#laravel-config">Laravel Configuration</a></li>
<li><a href="#troubleshooting">Troubleshooting</a></li>
</ol>
<p><a id="overview"></a></p>
<h2 id="overview">Overview</h2>
<p>The <em>Rublon PHP SDK library</em> is a client-side implementation
of the Rublon API written in PHP. The library includes methods for
embedding the Rublon API’s GUI in an HTML-based environment. The Rublon
PHP SDK forms a convenient PHP coding language facade for Rublon API’s
REST interface.</p>
<p><a id="use-cases"></a></p>
<h2 id="use-cases">Use Cases</h2>
<p>Rublon adds an extra layer of security by prompting the user to authenticate using an extra authentication method such as Mobile Push. Even if a malicious actor compromises the user’s password, the hacker be able to log in to the user’s account because the second secure factor will thwart them.</p>
<p>Rublon can add an extra layer of security in the following two use
cases:</p>
<ol type="1">
<li><strong>When a user signs in to a system</strong> (after the user
enters the correct password)</li>
<li><strong>When a user undergoes a security-sensitive
transaction</strong> (such as changing the password or conducting a
money transfer)</li>
</ol>
<p>When a user signs in to a system, the second authentication factor
should be initiated only after:
</p>
<ul>
<li>the user has successfully completed the first authentication factor (e.g., entered the correct password)
</li>
<li>the user’s unique username and email address have been gathered</li>
</ul>
<p><a id="auth-methods"></a></p>
<h2 id="supported-authentication-methods">Supported Authentication
Methods</h2>
<ul>
<li><a href="https://rublon.com/product/mobile-push" target="_blank">Mobile
Push</a> - Approve the authentication request by tapping a push
notification displayed on the Rublon Authenticator mobile app.</li>
<li><a href="https://rublon.com/product/mobile-passcodes" target="_blank">Mobile
Passcodes</a> (TOTP) - Enter the TOTP code (Time-Based One Time Password) using the Rublon Authenticator mobile app or a third-party authenticator app like Google Authenticator or Microsoft Authenticator.</li>
<li><a href="https://rublon.com/product/sms-passcodes" target="_blank">SMS
Passcodes</a> - Enter the verification code from the SMS sent to your
mobile phone number.</li>
<li><a href="https://rublon.com/product/qr-codes" target="_blank">QR
Codes</a> - Scan a QR code using the Rublon Authenticator mobile
app.</li>
<li><a href="https://rublon.com/product/email-link" target="_blank">Email
Links</a> - Click the verification link sent to your email address.</li>
<li><a href="https://rublon.com/product/security-keys/" target="_blank">WebAuthn/U2F
Security Keys</a> - Insert the security key into the USB port of your
computer and touch it.</li>
<li><a href="https://rublon.com/product/yubikey-otp/" target="_blank">YubiKey
OTP</a> - Insert the YubiKey and tap it to automatically enter the OTP
into the text field.</li>
</ul>
<p><a id="before-start"></a></p>
<h2 id="before-you-start">Before You Start</h2>
<p>Before you start implementing the Rublon PHP SDK library into your
code, you must create an application in the Rublon Admin Console. We
also recommend that you install the Rublon Authenticator mobile app for
Mobile Push, Mobile Passcode, and QR Code authentication methods.</p>
<p><a id="create-app"></a></p>
<h3 id="create-an-application-in-the-rublon-admin-console">Create an
Application in the Rublon Admin Console</h3>
<ol type="1">
<li>Sign up for the Rublon Admin Console.
<a href="https://rublon.com/doc/admin-console/#rublon-account-registration" target="_blank">Here’s
how</a>.
</li>
<li>In the Rublon Admin Console, go to the <strong>Applications</strong>
tab and click <strong>Add Application</strong>.</li>
<li>Enter a name for your application and then set the type to
<strong>Custom integration using PHP SDK</strong>.
</li>
<li>Click <strong>Save</strong> to add the new PHP SDK application in
the Rublon Admin Console.</li>
<li>Copy and save the values of <strong>System Token</strong> and
<strong>Secret Key</strong>. You are going to need these values
later.
</li>
</ol>
<p><a id="install-ra"></a></p>
<h3 id="optional-install-rublon-authenticator">Optional: Install Rublon
Authenticator</h3>
<p>For increased security of Multi-Factor Authentication (MFA),
end-users are recommended to install the
<a href="https://rublon.com/product/rublon-authenticator" target="_blank">Rublon
Authenticator</a> mobile app.
</p>
<p>Download the Rublon Authenticator for:</p>
<ul>
<li><a href="https://play.google.com/store/apps/details?id=com.rublon.authenticator&hl=en"
target="_blank">Android</a></li>
<li><a href="https://apps.apple.com/us/app/rublon-authenticator/id1434412791" target="_blank">iOS</a></li>
</ul>
<p>After installing the mobile app, users can authenticate using the
following authentication methods:</p>
<ul>
<li><a href="https://rublon.com/product/mobile-push" target="_blank">Mobile
Push</a></li>
<li><a href="https://rublon.com/product/mobile-passcodes" target="_blank">Mobile
Passcode</a></li>
<li><a href="https://rublon.com/product/qr-codes" target="_blank">QR
Code</a></li>
</ul>
<p>In some cases, users may not want to install any additional apps on
their phones. Also, some users own older phones that do not support
modern mobile applications. These users can authenticate using one of
the following authentication methods instead:</p>
<ul>
<li><a href="https://rublon.com/product/security-keys" target="_blank">WebAuthn/U2F
Security Keys</a></li>
<li><a href="https://rublon.com/product/sms-passcodes" target="_blank">SMS
Passcode</a></li>
<li><a href="https://rublon.com/product/email-link" target="_blank">Email
Link</a></li>
<li><a href="https://rublon.com/product/security-keys/" target="_blank">WebAuthn/U2F
Security Keys</a></li>
<li><a href="https://rublon.com/product/yubikey-otp" target="_blank">YubiKey
OTP</a></li>
</ul>
<p><a id="config"></a></p>
<h2 id="configuration">Configuration</h2>
<p>Follow the steps below to configure Rublon PHP SDK.</p>
<p><a id="init-assumptions"></a></p>
<h3 id="info-initial-assumptions">INFO: Initial Assumptions</h3>
<p>Let’s assume there is a superglobal session associative array
<code>$_SESSION</code>. It has access to an object that stores user data
of the currently logged-in user.
</p>
<p>The <code>$_SESSION</code> array will be used in PHP code examples
later in this document.</p>
<p><a id="modifying-library"></a></p>
<h3 id="info-modifying-the-library">INFO: Modifying the Library</h3>
<p>The <code>Rublon</code> class implements a few public methods, which,
when needed, can be overridden using class inheritance.</p>
<p>We strongly discourage you from modifying any part of the library, as
it usually leads to difficulties during library updates. If you need to
change the flow or internal structure of the <code>Rublon</code> or
<code>RublonCallback</code> classes, do not hesitate to subclass them
according to your needs.
</p>
<p><a id="init-library"></a></p>
<h3 id="initialize-the-library">Initialize the Library</h3>
<p>To initialize the Rublon PHP SDK library, you need to instantiate a
<code>Rublon</code> class object. Its constructor takes three
arguments.
</p>
<table>
<caption style="text-align: left">
<code>Rublon</code> class constructor arguments
</caption>
<thead>
<tr>
<th>
Name
</th>
<th>
Type
</th>
<th>
Description
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>$systemToken</code>
</td>
<td>
string
</td>
<td>
The System Token value you copied from the Rublon Admin Console.
</td>
</tr>
<tr>
<td>
<code>$secretKey</code>
</td>
<td>
string
</td>
<td>
The Secret Key value you copied from the Rublon Admin Console.
</td>
</tr>
<tr>
<td>
<code>$apiServer</code>
</td>
<td>
string
</td>
<td>
Rublon API Server URI<br><br>
Default: https://core.rublon.net
</td>
</tr>
</tbody>
</table>
<h4 id="example-php-code">Example PHP Code</h4>
<pre><code> require_once "libs/Rublon/Rublon.php";
$rublon = new Rublon(
"D166A6E9996A40F0A88252432FA5E490",
"913eda929c96cf52141b39f5717e25",
"https://core.rublon.net"
);</code></pre>
<p><a id="verify-conf"></a></p>
<h3 id="verify-configurationn">Verify Configuration</h3>
<p>The <code>Rublon::checkApplication()</code> method verifies the validity of the configuration. Your application should call this method every time you change or save the configuration. A configuration change can be, for example, changing the systemToken or secretKey.</p>
<table>
<caption><code>Rublon::checkApplication()</code> method arguments</caption>
<thead><tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr></thead>
<tbody>
<tr><td><code>appVer</code></td><td>string</td><td>The version of the current application.</td></tr>
<tr><td><code>params</code></td><td>array</td><td>Optional.<br/></br>Additional application parameters.</td></tr>
</tbody>
</table>
<p><code>Rublon::checkApplication()</code> may throw one of the following exceptions:</p>
<ul>
<li><strong>ApplicationNotFoundException</strong> - Invalid System Token</li>
<li><strong>InvalidSignatureException</strong> - Invalid Secret Key</li>
<li><strong>UnsupportedVersionException</strong> - Incorrect version of the application</li>
</ul>
<p><a id="perform-auth"></a></p>
<h3 id="perform-authentication">Perform Authentication</h3>
<p>The <code>Rublon::auth()</code> method uses the username to check the
user’s protection status and returns a URL address the user should be
redirected to in their web browser.</p>
<table>
<caption style="text-align: left">
<code>Rublon::auth()</code> method arguments
</caption>
<thead>
<tr>
<th>
Name
</th>
<th>
Type
</th>
<th>
Description
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>$callbackUrl</code>
</td>
<td>
string
</td>
<td>
The integrated system’s callback URL.<br><br>
Rublon will redirect the user to this URL after successful
authentication.
</td>
</tr>
<tr>
<td>
<code>$username</code>
</td>
<td>
string
</td>
<td>
The user’s username, which allows the user to sign in
</td>
</tr>
<tr>
<td>
<code>$userEmail</code>
</td>
<td>
string
</td>
<td>
The user’s email address, which allows to check the user’s protection
status and match the user to a Rublon account
</td>
</tr>
<tr>
<td>
<code>$params</code>
</td>
<td>
array
</td>
<td>
Additional transaction parameters (optional)
</td>
</tr>
<tr>
<td>
<code>$isPasswordless</code>
</td>
<td>
boolean
</td>
<td>
Whether the sign-in attempt is passwordless (optional and false by
default)
</td>
</tr>
</tbody>
</table>
<h4 id="example-php-code-1">Example PHP Code</h4>
<pre><code> /**
* An example method used to log the user in (integrated system's method)
*
* @param string $login
* @param string $password
*/
function login($login, $password) {
if (loginPreListener()) {
if ($user = authenticate($login, $password)) {
// The user has been authenticated.
$_SESSION["user"] = $user;
loginPostListener();
}
}
}
/**
* Listener (hook) invoked after a successful first factor user authentication,
* implemented for Rublon integration purposes.
*/
function loginPostListener() {
// Make sure that the user is not logged-in
unset($_SESSION['user']);
$rublon = new Rublon(
"D166A6E9996A40F0A88252432FA5E490",
"913eda929c96cf52141b39f5717e25",
"https://core.rublon.net"
);
try { // Initiate a Rublon authentication transaction
$authUrl = $rublon->auth(
$callbackUrl = "http://example.com?rublon=callback",
$_SESSION["user"]["login"], // Username
$_SESSION["user"]["email"] // User email
);
if (!empty($authUrl)) { // User protection is active
// Redirect the user's web browser to Rublon servers to verify the protection:
header('Location: ' . $authUrl);
} else {
// User is not protected by Rublon, so bypass the second factor.
header('Location: index.php');
}
} catch (UserDeniedException $e) {
// Access Denied
header('Location: ./');
} catch (UserBypassedException $e) {
// User bypassed
header('Location: ./');
} catch (RublonException $e) {
// An error occurred
die($e->getMessage());
}
}</code></pre>
<p><strong>Note:</strong> Make sure that your code checks that the user
is not signed in. The user should be signed in only after successful
Rublon authentication.</p>
<p><a id="final-auth"></a></p>
<h3 id="finalize-authentication">Finalize Authentication</h3>
<p>After successful authentication, Rublon redirects the user to the
callback URL. The callback flow continues and finalizes the
authentication process.</p>
<h4 id="input-params">Input Params</h4>
<p>The callback URL will receive input arguments in the URL address
itself (query string).</p>
<table>
<caption style="text-align: left">
Callback URL arguments
</caption>
<thead>
<tr>
<th>
Name
</th>
<th>
Type
</th>
<th>
Description
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>rublonState</code>
</td>
<td>
string
</td>
<td>
Authentication result: <code>ok</code>.
</td>
</tr>
<tr>
<td>
<code>rublonToken</code>
</td>
<td>
string
</td>
<td>
Access token (60 alphanumeric characters, upper- and lowercase), which
allows to verify the authentication using a background Rublon API
connection
</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> If the callback URL has been set to, e.g.,
<code>http://example.com/auth</code>, the params will be appended to the
URL address:
</p>
<p><code>http://example.com/auth?rublonState=ok&rublonToken=Kmad4hAS…</code></p>
<p><strong>Note:</strong> If you want to construct the callback URL
differently (e.g., by using mod_rewrite), you can set the callback URL’s
template using the meta-tags: <code>%rublonToken%</code> and
<code>%rublonState%</code>, like so:
</p>
<p><code>http://example.com/auth/%rublonState%/%rublonToken%</code></p>
<h4 id="handle-authentication-result">Handle Authentication Result</h4>
<p>After the callback is invoked, you need to instantiate a
<code>RublonCallback</code> class object for proper finalization of the
authentication process.
</p>
<table>
<caption style="text-align: left">
<code>RublonCallback</code> class constructor method arguments
</caption>
<thead>
<tr>
<th>
Name
</th>
<th>
Type
</th>
<th>
Description
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>$rublon</code>
</td>
<td>
Rublon
</td>
<td>
An instance of the <code>Rublon</code> class
</td>
</tr>
</tbody>
</table>
<p>Next, call the <code>RublonCallback::call()</code> method. It takes
two arguments:</p>
<table>
<caption style="text-align: left">
<code>RublonCallback::call()</code> method arguments
</caption>
<thead>
<tr>
<th>
Name
</th>
<th>
Type
</th>
<th>
Description
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>$successHandler</code>
</td>
<td>
callable
</td>
<td>
The name of the function/method, or an anonymous function/closure, to be
invoked on successful authentication
</td>
</tr>
<tr>
<td>
<code>$cancelHandler</code>
</td>
<td>
callable
</td>
<td>
The name of the function/method, or an anonymous function/closure, to be
invoked when the callback is canceled
</td>
</tr>
</tbody>
</table>
<table>
<caption style="text-align: left">
Arguments of the <code>$successHandler</code> function, passed to the
<code>RublonCallback::call()</code> method
</caption>
<thead>
<tr>
<th>
Name
</th>
<th>
Type
</th>
<th>
Description
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>$username</code>
</td>
<td>
string
</td>
<td>
The user’s unique username in the integrated system, that was passed as
an argument to the <code>Rublon::auth()</code> method
</td>
</tr>
<tr>
<td>
<code>$callback</code>
</td>
<td>
RublonCallback
</td>
<td>
An instance of the <code>RublonCallback</code> class
</td>
</tr>
</tbody>
</table>
<table style="min-width: 600px;">
<caption style="text-align: left">
Arguments of the <code>$cancelHandler</code> function, passed to the <code>RublonCallback::call()</code>
method
</caption>
<thead>
<tr>
<th>
Name
</th>
<th>
Type
</th>
<th>
Description
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>$callback</code>
</td>
<td>
RublonCallback
</td>
<td>
An instance of the <code>RublonCallback</code> class
</td>
</tr>
</tbody>
</table>
<h4 id="example-php-code-2">Example PHP Code</h4>
<p>An example portraying how to use the <code>RublonCallback</code>
class in the callback:</p>
<pre><code> $rublon = new Rublon(
"D166A6E9996A40F0A88252432FA5E490",
"913eda929c96cf52141b39f5717e25",
"https://code.rublon.net"
);
try {
$callback = new RublonCallback($rublon);
$callback->call(
$successHandler = function($username, RublonCallback $callback) {
// The user is finally logged in
$_SESSION["user"] = $username;
},
$cancelHandler = function(RublonCallback $callback) {
// Cancel the authentication process
header("Location: ./login");
exit;
}
);
// The authentication process was successful, redirect to the main page:
header("Location: ./");
exit;
} catch (RublonException $e) {
// Please handle this error in the better way
die($e->getMessage());
}</code></pre>
<p><a id="laravel-config"></a></p>
<h2 id="laravel-configuration">Laravel Configuration</h2>
<p>This Laravel configuration example uses the
<a href="https://laravel.com/docs/9.x/starter-kits#laravel-breeze" target="_blank">Breeze</a>
starting kit.
</p>
<ol type="1">
<li>
<p>After you create the application and install Breeze, you need to
add Rublon PHP SDK:</p>
<p><code>composer require Rublon/rublon-sdk-php</code></p>
</li>
<li>
<p>Add those to .env:</p>
<p><code>RUBLON_TOKEN="your rublon token"</code></p>
<p><code>RUBLON_KEY="your rublon key"</code></p>
<p><code>RUBLON_URL="https://core.rublon.net"</code></p>
</li>
<li>
<p>Create new route for Rublon callback in routes/auth.php:</p>
<p><code>Route::get('rublon-callback', [AuthenticatedSessionController::class, 'rublonCallback'])->name('rublon-callback');</code>
</p>
</li>
<li>
<p>Modify the store method in the controller:</p>
<p><code>Http/Controllers/Auth/AuthenticatedSessionController.php</code></p>
<pre><code> public function store(LoginRequest $request)
{
$request->authenticate();
$rublon = new Rublon(
env('RUBLON_TOKEN'),
env('RUBLON_KEY'),
env('RUBLON_URL'),
);
try { // Initiate a Rublon authentication transaction
$url = $rublon->auth(
$callbackUrl = url('/rublon-callback'),
Auth::user()->email, // User email used as username
Auth::user()->email // User email
);
if (!empty($url)) {
Auth::logout();
return redirect()->away($url);
} else {
// User is not protected by Rublon, so bypass the second factor.
$request->session()->regenerate();
return redirect()->to('dashboard');
}
} catch (UserBypassedException $e) {
return redirect()->to('login');
} catch (RublonException $e) {
// An error occurred
die($e->getMessage());
}