-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6587dea
Showing
9 changed files
with
1,463 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
vendor |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
This is free and unencumbered software released into the public domain. | ||
|
||
Anyone is free to copy, modify, publish, use, compile, sell, or | ||
distribute this software, either in source code form or as a compiled | ||
binary, for any purpose, commercial or non-commercial, and by any | ||
means. | ||
|
||
In jurisdictions that recognize copyright laws, the author or authors | ||
of this software dedicate any and all copyright interest in the | ||
software to the public domain. We make this dedication for the benefit | ||
of the public at large and to the detriment of our heirs and | ||
successors. We intend this dedication to be an overt act of | ||
relinquishment in perpetuity of all present and future rights to this | ||
software under copyright law. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
For more information, please refer to <http://unlicense.org/> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# Acloud | ||
|
||
Unofficial PHP client for Apple iCloud services. | ||
|
||
> Apple and iCloud are trademarks of Apple Inc. | ||
| Service | Supported | | ||
|-|-| | ||
| Calendar | ❌ | | ||
| Contacts | ✅ Supported | | ||
| Drive | ❌ | | ||
| Find My | ❌ | | ||
| Friends | ❌ | | ||
| Mail | ❌ | | ||
| Notes | ❌ | | ||
| Photos | ❌ | | ||
| Reminders | ❌ | | ||
|
||
Feel free to add support for services by submitting a pull request. | ||
|
||
## Installation | ||
|
||
``` | ||
composer require thisispiers/acloud | ||
``` | ||
|
||
## Usage | ||
|
||
The tokens and cookies used for signing in are saved to the file path passed as the first argument to the constructor of `Session`. If you need to override this feature, pass in `null` or an empty string and use `getState()` and `getHttpCookieJar()`. | ||
|
||
If a verification code is needed for signing in, `signIn()` will return the string `"MFA"` or the obfuscated phone number the code was sent to. Retrieve the verification code from the user and pass it to `verifyMFACode()`. | ||
|
||
Make sure to check `isSignedIn()` after calling `signIn()` and `verifyMFACode()`. | ||
|
||
Here's a basic example: | ||
|
||
```php | ||
<?php | ||
|
||
require __DIR__ . '/vendor/autoload.php'; | ||
|
||
$acloud = new \thisispiers\Acloud\Session(__DIR__ . '/session'); | ||
if (!$acloud->isSignedIn()) { | ||
if (empty($_POST)) { | ||
?> | ||
<form method="POST"> | ||
<p>Username: <input type="text" name="username"></p> | ||
<p>Password: <input type="password" name="password"></p> | ||
<button type="submit">Sign in</button> | ||
</form> | ||
<?php | ||
} else if (isset($_POST['username']) && isset($_POST['password'])) { | ||
$result = $acloud->signIn($_POST['username'], $_POST['password']); | ||
if ($signIn !== true) { | ||
if ($signIn === 'MFA') { | ||
echo '<p>Verification code sent to your device(s)</p>'; | ||
} else { | ||
echo '<p>Verification code sent to ' . htmlspecialchars($signIn) . '</p>'; | ||
} | ||
?> | ||
<form method="POST"> | ||
Verification code: <input type="text" inputmode="numeric" name="verificationCode"> | ||
<button type="submit">Sign in</button> | ||
</form> | ||
<?php | ||
} | ||
} else if (isset($_POST['verificationCode'])) { | ||
$acloud->verifyMFACode($_POST['verificationCode']); | ||
if (!$acloud->isSignedIn()) { | ||
echo '<p>Verification code invalid. Please try again.</p>'; | ||
} | ||
} | ||
} | ||
|
||
if ($acloud->isSignedIn()) { | ||
$contacts = new \thisispiers\Acloud\Contacts($acloud); | ||
$allContacts = $contacts->list(); | ||
} | ||
``` | ||
|
||
### API | ||
|
||
```php | ||
class Session | ||
{ | ||
public function __construct(?string $path = ''); | ||
|
||
public function getHttpCookieJar(): \GuzzleHttp\Cookie\CookieJarInterface; | ||
|
||
public function loadState(?string $path = ''): bool; | ||
|
||
public function saveState(): bool; | ||
|
||
public function getState(): array; | ||
|
||
public function isSignedIn(): bool; | ||
|
||
public function signIn(string $username, string $password): true|string; | ||
|
||
public function sendMFACodeSMS(): false|string; | ||
|
||
public function verifyMFACode(string $code): bool; | ||
} | ||
``` | ||
|
||
Once signed in, pass the `Session` object into the service class constructor. | ||
|
||
```php | ||
class Contacts | ||
{ | ||
public function __construct(Session $session); | ||
|
||
public function list(): array; | ||
|
||
public function create(array $contacts): true; | ||
|
||
public function update(array $contacts): true; | ||
|
||
public function delete(array $contacts): true; | ||
} | ||
``` | ||
|
||
Read through the source code to find out which exceptions may be thrown. | ||
|
||
--- | ||
|
||
### Thanks | ||
|
||
Based on the following repositories: | ||
|
||
- <https://github.com/foxt/icloud.js> | ||
- <https://github.com/MauriceConrad/iCloud-API> | ||
- <https://github.com/prabhu/iCloud> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "thisispiers/acloud", | ||
"description": "Unofficial PHP client for Apple iCloud services", | ||
"version": "0.1.0", | ||
"type": "library", | ||
"keywords": ["icloud", "apple", "appleid", "client", "sdk", "contacts"], | ||
"license": "Unlicense", | ||
"autoload": { | ||
"psr-4": { | ||
"thisispiers\\Acloud\\": "src/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "thisispiers" | ||
} | ||
], | ||
"require": { | ||
"php": "^8", | ||
"guzzlehttp/guzzle": "^7.0" | ||
} | ||
} |
Oops, something went wrong.