departmentofhealth/yii2-dohclient

doh oauth2 client

0.9.2 2017-02-21 04:07 UTC

This package is not auto-updated.

Last update: 2024-04-27 17:26:31 UTC


README

การติดตั้ง

สามารถติดตั้งผ่าน composer โดยรันคำสั่ง

php composer require --prefer-dist departmentofhealth/yii2-dohclient "*"

หรือเพิ่มคำสั่งนี้

"departmentofhealth/yii2-dohclient": "*"

ที่ไฟล์ composer.json ในส่วนของ require

ลงทะเบียนเข้าใช้งาน DOH SSO

  • ลงทะเบียนเข้าใช้งานที่ http://sso.anamai.moph.go.th
  • กรอกข้อมูลส่วนตัว
  • สร้าง Application และกรอก redirect url จะได้ clientID, clientSecret

การใช้งานร่วมกับ yii2-user

ตั้งค่า authClientCollection ที่ main.php ใสส่วนของ components

...

        'authClientCollection' => [
            'class'   => \yii\authclient\Collection::className(),
            'httpClient' => [
                'transport' => 'yii\httpclient\CurlTransport',
            ],
            'clients' => [
               'doh' => [
                    'class' => 'departmentofhealth\yii2\dohclient\DohClientDektrium',
                    'clientId' => '<clientID>',
                    'clientSecret' => '<ClientSecret>',
                ],
            ],
        ],
...

ทำการ override view yii2-user และเรียกใช้งาน widget ที่หน้า login

<?php
    $authAuthChoice = AuthChoice::begin([
        'baseAuthUrl' => ['/user/security/auth'],
        'popupMode' => false,
        'options'=>[
            'class'=>'auth-clients text-center',
        ]
    ]);
    echo 'Login with: ';
    foreach ($authAuthChoice->getClients() as $key => $client): ?>
<?= $authAuthChoice->clientLink($client,strtoupper($key));?>
<?php endforeach; ?>
<?php AuthChoice::end(); ?>