diff --git a/README.md b/README.md index 9f3f3d75e..b89d804c9 100644 --- a/README.md +++ b/README.md @@ -28,45 +28,6 @@ If you'd like to reuse or repost something, feel free to hit us up at info@spati This project and the Laravel framework are open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT). -## Apple sign-in - -Every 6 months, the token for Sign-in with Apple expires, this can be renewed using the "Spatie apple login - private key" in our team's 1Password vault and the following ruby script: - -```ruby -require 'jwt' - -key_file = 'key.txt' -team_id = '' # Found in the top right when signed in on the Apple developer site -client_id = 'be.spatie.website' -key_id = '' # The key ID, found here https://developer.apple.com/account/resources/authkeys/list - -ecdsa_key = OpenSSL::PKey::EC.new IO.read key_file - -headers = { -'kid' => key_id -} - -claims = { - 'iss' => team_id, - 'iat' => Time.now.to_i, - 'exp' => Time.now.to_i + 86400*180, - 'aud' => 'https://appleid.apple.com', - 'sub' => client_id, -} - -token = JWT.encode claims, ecdsa_key, 'ES256', headers - -puts token -``` - -Then execute it using - -```shell -ruby client_secret.rb -``` - -Which gives you a new token that is valid for 6 months. - ## GeoIP lookup We use Maxmind's geo IP dataset to provide PPP based on IP location. This is built using the excellent [laravel-geoip](https://lyften.com/projects/laravel-geoip) package. diff --git a/app/Http/Controllers/AppleSocialiteController.php b/app/Http/Controllers/AppleSocialiteController.php deleted file mode 100644 index ccc894117..000000000 --- a/app/Http/Controllers/AppleSocialiteController.php +++ /dev/null @@ -1,74 +0,0 @@ -reflash(); - - if (auth()->check()) { - /* - * If somebody is already logged in, the user wants to - * connect their Apple account. Remember who's logged in. - */ - session()->put('auth-user-id', auth()->user()->id); - } - - return Socialite::driver('apple')->redirect(); - } - - public function callback(): View - { - session()->replace(json_decode(request('state'), true)); - - $appleUser = Socialite::driver('apple')->user(); - - $user = $this->retrieveUser($appleUser); - - $user->update([ - 'apple_id' => $appleUser->getId(), - ]); - - auth()->login($user, true); - - flash()->success('You have been logged in'); - - return view('auth.appleCallback'); - } - - protected function retrieveUser(SocialiteUser $appleUser): User - { - if (session('auth-user-id')) { - /* - * If there already was a local user created for the email used - * on Apple, then let's use that local user - */ - return User::find(session('auth-user-id')); - } - - /* - * Somebody tries to login via Apple that already - * has an account with this email. - * We'll link this Apple profile to this account. - */ - if ($appleUser->getEmail() && $user = User::where('email', $appleUser->getEmail())->first()) { - return $user; - } - - return User::firstOrCreate([ - 'apple_id' => $appleUser->getId(), - ], [ - 'password' => bcrypt(Str::random()), - 'email' => $appleUser->getEmail(), - 'name' => $appleUser->getName() ?? $appleUser->getEmail(), - ]); - } -} diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index c8265567c..d3d6cc12e 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -45,17 +45,6 @@ public function disconnect(): RedirectResponse return redirect()->route('profile'); } - public function disconnectApple(): RedirectResponse - { - auth()->user()->update([ - 'apple_id' => null, - ]); - - flash()->success('Apple account disconnected.'); - - return redirect()->route('profile'); - } - public function delete(): RedirectResponse { /** @var \App\Models\User $user */ diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 17f254b83..c1b59e589 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -3,11 +3,9 @@ namespace App\Providers; use App\Domain\Shop\Models\License; -use App\Support\Socialite\SignInWithAppleProvider; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; -use Laravel\Socialite\Facades\Socialite; class AuthServiceProvider extends ServiceProvider { @@ -30,12 +28,5 @@ public function boot(): void return $license; }); - - Socialite::extend('apple', function () { - return Socialite::buildProvider( - SignInWithAppleProvider::class, - config('services.apple'), - ); - }); } } diff --git a/app/Support/Socialite/SignInWithAppleProvider.php b/app/Support/Socialite/SignInWithAppleProvider.php deleted file mode 100644 index fa18cc4ad..000000000 --- a/app/Support/Socialite/SignInWithAppleProvider.php +++ /dev/null @@ -1,89 +0,0 @@ -buildAuthUrlFromBase('https://appleid.apple.com/auth/authorize', $state); - } - - protected function getState() - { - return json_encode(Arr::except(session()->all(), ['_flash', '_previous'])); - } - - protected function getCodeFields($state = null) - { - return array_merge([ - 'client_id' => $this->clientId, - 'redirect_uri' => $this->redirectUrl, - 'scope' => $this->formatScopes($this->getScopes(), $this->scopeSeparator), - 'response_type' => 'code', - 'response_mode' => 'form_post', - ], $this->usesState() ? ['state' => $state] : [], $this->parameters); - } - - protected function getTokenUrl() - { - return 'https://appleid.apple.com/auth/token'; - } - - public function getAccessToken($code) - { - $response = $this->getHttpClient()->post($this->getTokenUrl(), [ - 'headers' => [ - 'Authorization' => 'Basic '.base64_encode("{$this->clientId}:{$this->clientSecret}"), - ], - 'body' => $this->getTokenFields($code), - ]); - - return json_decode($response->getBody()->getContents(), true)['access_token']; - } - - protected function getUserByToken($token) - { - $claims = explode('.', $token)[1]; - - return json_decode(base64_decode($claims), true); - } - - public function user() - { - $response = $this->getAccessTokenResponse($this->getCode()); - - $user = $this->mapUserToObject( - $this->getUserByToken(Arr::get($response, 'id_token')) - ); - - return $user - ->setToken(Arr::get($response, 'id_token')) - ->setRefreshToken(Arr::get($response, 'refresh_token')) - ->setExpiresIn(Arr::get($response, 'expires_in')); - } - - protected function mapUserToObject(array $user) - { - $userDetails = request()->json('user'); - - if (Arr::has($userDetails, 'name')) { - $fullName = implode(' ', $user['name'] = $userDetails['name']); - } - - return (new User())->setRaw($user)->map([ - 'id' => $user['sub'], - 'name' => $fullName ?? null, - 'email' => $user['email'] ?? null, - ]); - } -} diff --git a/config/services.php b/config/services.php index c5fc7ab1f..839d2d884 100644 --- a/config/services.php +++ b/config/services.php @@ -78,12 +78,6 @@ 'package_training' => env('PROMO_CODE_PACKAGE_TRAINING'), ], - 'apple' => [ - 'redirect' => env('APPLE_CALLBACK_URL'), - 'client_id' => env('APPLE_ID'), - 'client_secret' => env('APPLE_SECRET'), - ], - 'mailcoach' => [ 'token' => env('MAILCOACH_TOKEN'), ], diff --git a/database/migrations/2024_01_03_165234_remove_apple_id_column_from_users.php b/database/migrations/2024_01_03_165234_remove_apple_id_column_from_users.php new file mode 100644 index 000000000..925efe6a3 --- /dev/null +++ b/database/migrations/2024_01_03_165234_remove_apple_id_column_from_users.php @@ -0,0 +1,14 @@ +dropColumn('apple_id'); + }); + } +}; diff --git a/resources/views/auth/appleCallback.blade.php b/resources/views/auth/appleCallback.blade.php deleted file mode 100644 index f60cbdaf4..000000000 --- a/resources/views/auth/appleCallback.blade.php +++ /dev/null @@ -1,22 +0,0 @@ - - -
- - - -Log in without password and check your sponsor status.
@endif -Log in without password.
- @endif -