diff --git a/app/config/providers.php b/app/config/providers.php index 703bbef264..490c173555 100644 --- a/app/config/providers.php +++ b/app/config/providers.php @@ -73,12 +73,12 @@ return [ 'enabled' => true, 'mock' => false, ], - // 'apple' => [ - // 'developers' => 'https://developer.apple.com/', - // 'icon' => 'icon-apple', - // 'enabled' => false, - // 'mock' => false, - // ], + 'apple' => [ + 'developers' => 'https://developer.apple.com/', + 'icon' => 'icon-apple', + 'enabled' => true, + 'mock' => false, + ], 'amazon' => [ 'developers' => 'https://developer.amazon.com/apps-and-games/services-and-apis', 'icon' => 'icon-amazon', diff --git a/public/images/oauth2/apple.png b/public/images/oauth2/apple.png index b0fdfd14f0..98086e8048 100644 Binary files a/public/images/oauth2/apple.png and b/public/images/oauth2/apple.png differ diff --git a/src/Appwrite/Auth/OAuth2/Apple.php b/src/Appwrite/Auth/OAuth2/Apple.php index 427b78debb..22ed29561a 100644 --- a/src/Appwrite/Auth/OAuth2/Apple.php +++ b/src/Appwrite/Auth/OAuth2/Apple.php @@ -138,4 +138,33 @@ class Apple extends OAuth2 return $this->user; } + + protected function getToken($p8) + { + $keyfile = 'AuthKey_AABBCC1234.p8'; # <- Your AuthKey file + $keyid = '4LFF7TZ6Q5'; # <- Your Key ID + $teamid = 'YJHMCSNREU'; # <- Your Team ID (see Developer Portal) + $bundleid = 'test2.appwrite.io'; # <- Your Bundle ID + $url = 'https://api.development.push.apple.com'; # <- development url, or use http://api.push.apple.com for production environment + $token = 'e2c48ed32ef9b018........'; # <- Device Token + + function base64($data) { + return rtrim(strtr(base64_encode(json_encode($data)), '+/', '-_'), '='); + } + + $message = '{"aps":{"alert":"Hi there!","sound":"default"}}'; + + $key = openssl_pkey_get_private('file://'.$keyfile); + + $header = ['alg'=>'ES256', 'kid'=>$keyid]; + $claims = ['iss'=>$teamid, 'iat'=>time()]; + + $header_encoded = base64($header); + $claims_encoded = base64($claims); + + $signature = ''; + openssl_sign($header_encoded . '.' . $claims_encoded, $signature, $key, 'sha256'); + $jwt = $header_encoded . '.' . $claims_encoded . '.' . base64_encode($signature); + + } }