Commit 068a658418258f25e302175eeada0ecf3eb4c7c5

Authored by oji
1 parent a15ede0912
Exists in master

add check SSO'

Showing 1 changed file with 39 additions and 1 deletions Inline Diff

1 ## SampleSso 1 ## SampleSso
2 2
3 SAMPLE SSO 3 SAMPLE SSO
4 4
5 Cara Install 5 Cara Install
6 ---- 6 ----
7 7
8 Via Terminal: 8 Via Terminal:
9 ``` 9 ```
10 composer install 10 composer install
11 chmod -R guo+w storage 11 chmod -R guo+w storage
12 cp .env.example .env 12 cp .env.example .env
13 ``` 13 ```
14 Atur pengaturan database pada file .env 14 Atur pengaturan database pada file .env
15 15
16 ``` 16 ```
17 DB_CONNECTION=mysql 17 DB_CONNECTION=mysql
18 DB_HOST=127.0.0.1 18 DB_HOST=127.0.0.1
19 DB_PORT=3306 19 DB_PORT=3306
20 DB_DATABASE=grandmaster 20 DB_DATABASE=grandmaster
21 DB_USERNAME=root 21 DB_USERNAME=root
22 DB_PASSWORD= 22 DB_PASSWORD=
23 ``` 23 ```
24 Atur pengaturan SSO Client ID pada file .env 24 Atur pengaturan SSO Client ID pada file .env
25 25
26 ``` 26 ```
27 SSO_CLIENT_ID= #3rd Party client Id (client id dari aplikasi SSO) 27 SSO_CLIENT_ID= #3rd Party client Id (client id dari aplikasi SSO)
28 SSO_CLIENT_SECRET= #3rd Party client secret (client secret dari aplikasi SSO) 28 SSO_CLIENT_SECRET= #3rd Party client secret (client secret dari aplikasi SSO)
29 SSO_REDIRECT_URI= #3rd Party url redirect or url to handle callback (url redirect aplikasi anda jika berhasil login SSO) 29 SSO_REDIRECT_URI= #3rd Party url redirect or url to handle callback (url redirect aplikasi anda jika berhasil login SSO)
30 SSO_TARGET_URI="https://sso.riau.go.id/" #SSO Riau portal 30 SSO_TARGET_URI="https://sso.riau.go.id/" #SSO Riau portal
31 ``` 31 ```
32 Migrate database dan seeder 32 Migrate database dan seeder
33 33
34 ``` 34 ```
35 php artisan migrate --seed #username dan password akan muncul setelah migrate 35 php artisan migrate --seed #username dan password akan muncul setelah migrate
36 ``` 36 ```
37
38 Check SSO session : app\Http\Controllers\Sso.php
39
40 ```
41 public function check()
42 {
43 $objSso = new SsoClientLibrary();
44 $objSso->ssoRequest();
45 }
46
47 ```
48
49 Consume SSO session : app\Http\Controllers\Sso.php
50
51 ```
52 public function callback(Request $request)
53 {
54 if (isset($request->code) && $request->code != '') {
55 $objSso = new SsoClientLibrary();
56 $data_access_token = $objSso->ssoCallback();
57 if (!empty($data_access_token)) {
58 $data_access_token = json_decode($data_access_token);
59 $access_token = $data_access_token->access_token; // store access_token within the session if needed?
60 }
61
62 if ($access_token != '') {
63 //fetch ssoUserInfo
64 $ssoUserInfo = $objSso->ssoUserInfo($access_token);
65 $ssoUserInfo = json_decode($ssoUserInfo);
66
67 // check if sso_email already mapped or not
68 $user = User::where('sso_email', $ssoUserInfo->email)->first();
69 // mapping to local database
70 }
71 }
72 }
73
74 ```
75