diff --git a/app/Classes/Modules/Accounts/ControllersLogic/CrossAuthenticateUserLogic.php b/app/Classes/Modules/Accounts/ControllersLogic/CrossAuthenticateUserLogic.php new file mode 100644 index 00000000..5819a4f0 --- /dev/null +++ b/app/Classes/Modules/Accounts/ControllersLogic/CrossAuthenticateUserLogic.php @@ -0,0 +1,44 @@ + 'Cross Authentication', + 'message' => 'You have successfully logged in to your account' + ]; + } + + /** @var CrossAuthenticationProcessor */ + private $cressAuthenticationProcessor; + + + /** + * CrossAuthenticateUserLogic constructor. + * @param CrossAuthenticationProcessor $authenticationProcessor + */ + public function __construct(CrossAuthenticationProcessor $cressAuthenticationProcessor) + { + $this->cressAuthenticationProcessor = $cressAuthenticationProcessor; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\AccessUnauthorisedException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function logic(Request $request): JsonResponse { + return $this->response($this->cressAuthenticationProcessor->execute($request)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/DataTransferObjects/CrossAuthenticationCredentialsObject.php b/app/Classes/Modules/Accounts/DataTransferObjects/CrossAuthenticationCredentialsObject.php new file mode 100644 index 00000000..67abf905 --- /dev/null +++ b/app/Classes/Modules/Accounts/DataTransferObjects/CrossAuthenticationCredentialsObject.php @@ -0,0 +1,43 @@ +access_token = $access_token; + $this->platform = $platform; + } + + /** + * @return string + */ + public function getAccessToken(): string + { + return $this->access_token; + } + + /** + * @return string + */ + public function getPlatform(): int + { + return $this->platform; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Processors/CrossAuthenticationProcessor.php b/app/Classes/Modules/Accounts/Processors/CrossAuthenticationProcessor.php new file mode 100644 index 00000000..1f976a42 --- /dev/null +++ b/app/Classes/Modules/Accounts/Processors/CrossAuthenticationProcessor.php @@ -0,0 +1,70 @@ +canCrossAuthenticateUser = $canCrossAuthenticateUser; + $this->crossAuthenticatesUser = $crossAuthenticatesUser; + $this->generatesAuthenticationToken = $generatesAuthenticationToken; + $this->fetchesUser = $fetchesUser; + $this->authenticationRedirect = $authenticationRedirect; + } + + + /** + * @param Request $request + * @return array + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\AccessUnauthorisedException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function execute(Request $request): array { + + $object = new CrossAuthenticationCredentialsObject($request->input('access_token'), $request->input('platform')); + + $this->canCrossAuthenticateUser->passes($object); + + $this->crossAuthenticatesUser->execute($object); + + $user = $this->fetchesUser->execute(['email' => $object->getEmail()]); + + return ['access_token' => $this->generatesAuthenticationToken->execute($user), 'redirect_url' => $this->authenticationRedirect->url($user)]; + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Services/CrossAuthenticatesUser.php b/app/Classes/Modules/Accounts/Services/CrossAuthenticatesUser.php new file mode 100644 index 00000000..e76b9197 --- /dev/null +++ b/app/Classes/Modules/Accounts/Services/CrossAuthenticatesUser.php @@ -0,0 +1,44 @@ +getPlatform() == PlatformType::EXCHANGE) { + + // $headers = [ + // 'Content-Type' => 'application/json', + // 'Authorization' => 'Bearer ' . $object->getAccessToken(), + // ]; + // $client = new \GuzzleHttp\Client(['headers' => $headers]); + + // $response = $client->get('http://exchange-2.0.test/api/v1/account/user/list'); + + $response = Http::withToken($object->getAccessToken())->get('http://shipping-portal.test/api/v1/account/user/list')->object(); + dd($response); + + } + + if (! auth()->validate(['email' => $object->getEmail(), 'password' => $object->getPassword()])) { + throw new AccessUnauthorisedException('These credentials do not match our records.'); + } + + return true; + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Standards/Rules/CanCrossAuthenticateUser.php b/app/Classes/Modules/Accounts/Standards/Rules/CanCrossAuthenticateUser.php new file mode 100644 index 00000000..115a7ea6 --- /dev/null +++ b/app/Classes/Modules/Accounts/Standards/Rules/CanCrossAuthenticateUser.php @@ -0,0 +1,54 @@ +userCrossAuthenticationValidation = $userCrossAuthenticationValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + return true; + + } + + + /** + * @param AuthenticationCredentialsObject $object + * @return bool + * @throws RequestValidationException + */ + protected function validators($object): bool + { + return $this->userCrossAuthenticationValidation->validate($object); + } + + /** + * @param AuthenticationCredentialsObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Standards/Validators/UserCrossAuthenticationValidation.php b/app/Classes/Modules/Accounts/Standards/Validators/UserCrossAuthenticationValidation.php new file mode 100644 index 00000000..ec170dc7 --- /dev/null +++ b/app/Classes/Modules/Accounts/Standards/Validators/UserCrossAuthenticationValidation.php @@ -0,0 +1,43 @@ + $object->getAccesstoken(), + 'platform' => $object->getPlatform() + ]; + } + + /** + * @return array + */ + protected function rules(): array { + return [ + 'access_token' => 'required', + 'platform' => 'required' + ]; + } + + /** + * @return array + */ + protected function messages(): array { + return []; + } + + + + +} \ No newline at end of file diff --git a/app/Classes/ValueObjects/Constants/PlatformType.php b/app/Classes/ValueObjects/Constants/PlatformType.php new file mode 100644 index 00000000..d9ddd0e3 --- /dev/null +++ b/app/Classes/ValueObjects/Constants/PlatformType.php @@ -0,0 +1,9 @@ +execute($request); + } + +} diff --git a/app/Models/UserSocialAccount.php b/app/Models/UserSocialAccount.php new file mode 100644 index 00000000..b8f01866 --- /dev/null +++ b/app/Models/UserSocialAccount.php @@ -0,0 +1,11 @@ +id(); + $table->foreignId('user_id'); + $table->string('app_id')->nullable(); + $table->integer('platform')->default(0); + $table->softDeletes(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('user_social_accounts'); + } +} diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index bba317e6..983c7aad 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -23,7 +23,7 @@ class DatabaseSeeder extends Seeder $this->call(CountriesTableSeeder::class); $this->call(CurrenciesTableSeeder::class); - $this->call(CompaniesTableSeeder::class); - $this->call(OrdersTableSeeder::class); + // $this->call(CompaniesTableSeeder::class); + // $this->call(OrdersTableSeeder::class); } } \ No newline at end of file diff --git a/resources/assets/vue/components/accounts/forms/CrossPlatformLoginFormComponent.vue b/resources/assets/vue/components/accounts/forms/CrossPlatformLoginFormComponent.vue index 6cd0b199..6b44f6ba 100644 --- a/resources/assets/vue/components/accounts/forms/CrossPlatformLoginFormComponent.vue +++ b/resources/assets/vue/components/accounts/forms/CrossPlatformLoginFormComponent.vue @@ -37,7 +37,10 @@ methods:{ iframeEvent(event) { if(event.origin !== 'http://exchange-2.0.test') return; - console.log(event.data); + if (event.data.data) { + console.log(event.data.data.payload.access_token); + + } } }, mounted() { diff --git a/routes/account.php b/routes/account.php index 7a9e08df..cd4e33ae 100644 --- a/routes/account.php +++ b/routes/account.php @@ -6,9 +6,14 @@ Route::group(['prefix' => 'account', 'namespace' => 'Accounts', 'as' => 'account Route::post('/registration', 'CreateCustomerController@create')->name('registration.register'); + + Route::group(['prefix' => 'authentication', 'as' => 'authentication.'], function () { Route::group(['prefix' => 'login', 'as' => 'authenticate.'], function () { Route::post('/attempt', 'UserAuthenticationController@authenticate')->name('attempt'); + + Route::post('/cross-attempt', 'UserCrossAuthenticationController@authenticate')->name('cross.attempt'); + Route::post('/check_email', 'CheckEmailController@check')->name('email.check'); });