Created
April 25, 2018 05:23
-
-
Save ahmadwaliesipick/df785f64bcc5e5bdbc7b6ea56f8aa4bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use Illuminate\Http\Request; | |
use Illuminate\Support\Facades\Auth; | |
use Illuminate\Support\Facades\Redirect; | |
use Ixudra\Curl\Facades\Curl; | |
class HomeController extends Controller | |
{ | |
/** | |
* Create a new controller instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
$this->middleware('auth'); | |
} | |
/** | |
* Show the application dashboard. | |
* | |
* @return \Illuminate\Http\Response | |
*/ | |
public function index() | |
{ | |
return view('home'); | |
} | |
public function ssoLogin(Request $request){ | |
//$response = $this->getToken(); | |
$response = $request->token; | |
$token = $response; | |
$id = Auth::user()->email; | |
$ssokey = "7MpszrQpO95p7H"; | |
$idAndKey = $id . $ssokey; | |
$salt = $this->dumb_base64url_decode($token); | |
//dd($salt); | |
$hashed = hash_pbkdf2("sha1", $idAndKey, $salt, 1000, 24, true); | |
$key = $this->dumb_base64url_encode($hashed); | |
$url = 'https://automate.myabsorb.com/Account/ExternalLoginCallback?id='.Auth::user()->email.'&key='.$key; | |
return Redirect::to($url); | |
} | |
public function getToken(){ | |
$response = Curl::to('https://automate.myabsorb.com/Account/ExternalLogin') | |
->allowRedirect(true) | |
->withContentType('application/json') | |
->get(); | |
// $response = $response; | |
return $response; | |
} | |
public function getTokens($key){ | |
$data =[ | |
'url'=>'https://automate.myabsorb.com/Account/ExternalLoginCallback?id='.Auth::user()->email.'&key='.$key | |
]; | |
return $data; | |
/* try{ | |
//dd('https://automate.myabsorb.com/Account/ExternalLoginCallback?id=umar.nawab@esipick.com&key='.$key); | |
$url = 'https://automate.myabsorb.com/Account/ExternalLoginCallback?id=umar.nawab@esipick.com&key='.$key; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_HEADER, true); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
$result = curl_exec($ch); | |
dd($result); | |
if (preg_match('~Location: (.*)~i', $result, $match)) { | |
$location = trim($match[1]); | |
dd($location); | |
} | |
} catch (Exception $e) { | |
//return json_encode((string)$e->getResponse()->getBody()); | |
}*/ | |
} | |
function dumb_base64url_encode($bin) { | |
return preg_replace_callback( | |
'/(=*)$/', | |
function($matches){ | |
return strlen($matches[0]); | |
}, | |
str_replace( | |
['+', '/'], | |
['-', '_'], | |
base64_encode($bin) | |
), | |
1 | |
); | |
} | |
function dumb_base64url_decode($str) { | |
return base64_decode( | |
str_replace( | |
['-', '_'], | |
['+', '/'], | |
substr($str, 0, -1) | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment