aldinokemal

BBKKP - SsoBrokerTrait

Apr 5th, 2022 (edited)
1,128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.36 KB | None | 0 0
  1. <?php
  2.  
  3. use Jasny\SSO\Broker\Broker;
  4.  
  5. trait SsoBrokerTrait
  6. {
  7.     public function attach()
  8.     {
  9.         $broker = new Broker(
  10.             env('SSO_SERVER') . '/sso/attach',
  11.             env('SSO_BROKER_ID'),
  12.             env('SSO_BROKER_SECRET')
  13.         );
  14.  
  15.         // Handle error from SSO server
  16.         if (isset($_GET['sso_error'])) {
  17.             return view("errors.custom")->with([
  18.                 'code'    => 400,
  19.                 'info'    => "SSO ERROR",
  20.                 'message' => $_GET['sso_error'],
  21.             ]);
  22.         }
  23.  
  24.         // Handle verification from SSO server
  25.         if (isset($_GET['sso_verify'])) {
  26.             $broker->verify($_GET['sso_verify']);
  27.  
  28.             $url         = (!empty($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  29.             $redirectUrl = preg_replace('/sso_verify=\w+&|[?&]sso_verify=\w+$/', '', $url);
  30.             return redirect($redirectUrl);
  31.         }
  32.  
  33.         // Attach through redirect if the client isn't attached yet.
  34.         if (!$broker->isAttached()) {
  35.             $returnUrl = (!empty($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  36.             $attachUrl = $broker->getAttachUrl(['return_url' => $returnUrl]);
  37.  
  38.             return redirect($attachUrl);
  39.         }
  40.  
  41.         return $broker;
  42.     }
  43. }
  44.  
Add Comment
Please, Sign In to add comment