forked from LukeTowers/oc-eezeauth-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroutes.php
More file actions
65 lines (55 loc) · 1.83 KB
/
routes.php
File metadata and controls
65 lines (55 loc) · 1.83 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
<?php
use GuzzleHttp\Client;
use Backend\Models\User;
use Backend\Classes\AuthManager;
use LukeTowers\EEZEAuth\Models\Settings;
Route::post('luketowers/eezeauth', function () {
$token = post('token');
$clientId = Settings::get('client_id');
$clientSecret = Settings::get('client_secret');
$options = [
'base_uri' => "https://eeze.io/api/v1/",
'http_errors' => true,
'headers' => [
'Content-Type' => 'application/json',
'Client-Id' => $clientId,
'Client-Secret' => $clientSecret,
]
];
if (!empty($this->token)) {
$options['headers']['X-Shopify-Access-Token'] = $this->token;
}
$httpClient = new Client($options);
try {
$response = $httpClient->request('GET', "did-auth/challenge/$token/user", []);
$data = json_decode($response->getBody());
} catch (\Exception $ex) {
// API is currently down, so just default to hard coded user information
$data = [
'first_name' => 'Joe',
'last_name' => 'Bloggins',
'email' => 'joe.bloggins@example.com',
];
}
// Retrieve or authenticate the user
try {
$user = User::where('email', $data['email'])->firstOrFail();
} catch (\Exception $ex) {
$pass = Str::random(50);
$data['password'] = $pass;
$data['password_confirmation'] = $pass;
$data['login'] = $data['email'];
$user = User::create($data);
$roleId = Settings::get('role_id');
if (!empty($roleId)) {
$user->role_id = $roleId;
$user->save();
}
}
// Authenticate the user
$auth = AuthManager::instance();
$auth->logout();
$auth->login($user);
// Load the backend
return Redirect::to(Backend::url('backend'));
})->middleware('web');