PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 1.6.9
JetBackup – Backup, Restore & Migrate v1.6.9
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / com / lib / Dropbox / AuthInfo.php
backup / com / lib / Dropbox Last commit date
Exception 8 years ago WebAuthException 8 years ago certs 8 years ago AppInfo.php 8 years ago AppInfoLoadException.php 8 years ago ArrayEntryStore.php 8 years ago AuthBase.php 8 years ago AuthInfo.php 8 years ago AuthInfoLoadException.php 8 years ago Checker.php 8 years ago Client.php 8 years ago Curl.php 8 years ago CurlStreamRelay.php 8 years ago DeserializeException.php 8 years ago DropboxMetadataHeaderCatcher.php 8 years ago Exception.php 8 years ago Host.php 8 years ago HttpResponse.php 8 years ago OAuth1AccessToken.php 8 years ago OAuth1Upgrader.php 8 years ago Path.php 8 years ago RequestUtil.php 8 years ago RootCertificates.php 8 years ago SSLTester.php 8 years ago Security.php 8 years ago StreamReadException.php 8 years ago Util.php 8 years ago ValueStore.php 8 years ago WebAuth.php 3 years ago WebAuthBase.php 3 years ago WebAuthNoRedirect.php 8 years ago WriteMode.php 8 years ago autoload.php 8 years ago strict.php 8 years ago
AuthInfo.php
86 lines
1 <?php
2 namespace Dropbox;
3
4 /**
5 * This class contains methods to load an AppInfo and AccessToken from a JSON file.
6 * This can help simplify simple scripts (such as the example programs that come with the
7 * SDK) but is probably not useful in typical Dropbox API apps.
8 *
9 */
10 final class AuthInfo
11 {
12 /**
13 * Loads a JSON file containing authorization information for your app. 'php authorize.php'
14 * in the examples directory for details about what this file should look like.
15 *
16 * @param string $path
17 * Path to a JSON file
18 * @return array
19 * A <code>list(string $accessToken, Host $host)</code>.
20 *
21 * @throws AuthInfoLoadException
22 */
23 static function loadFromJsonFile($path)
24 {
25 if (!file_exists($path)) {
26 throw new AuthInfoLoadException("File doesn't exist: \"$path\"");
27 }
28
29 $str = Util::stripUtf8Bom(file_get_contents($path));
30 $jsonArr = json_decode($str, true, 10);
31
32 if (is_null($jsonArr)) {
33 throw new AuthInfoLoadException("JSON parse error: \"$path\"");
34 }
35
36 return self::loadFromJson($jsonArr);
37 }
38
39 /**
40 * Parses a JSON object to build an AuthInfo object. If you would like to load this from a file,
41 * please use the @see loadFromJsonFile method.
42 *
43 * @param array $jsonArr
44 * A parsed JSON object, typcally the result of json_decode(..., true).
45 * @return array
46 * A <code>list(string $accessToken, Host $host)</code>.
47 *
48 * @throws AuthInfoLoadException
49 */
50 private static function loadFromJson($jsonArr)
51 {
52 if (!is_array($jsonArr)) {
53 throw new AuthInfoLoadException("Expecting JSON object, found something else");
54 }
55
56 // Check access_token
57 if (!array_key_exists('access_token', $jsonArr)) {
58 throw new AuthInfoLoadException("Missing field \"access_token\"");
59 }
60
61 $accessToken = $jsonArr['access_token'];
62 if (!is_string($accessToken)) {
63 throw new AuthInfoLoadException("Expecting field \"access_token\" to be a string");
64 }
65
66 // Check for the optional 'host' field
67 if (!array_key_exists('host', $jsonArr)) {
68 $host = null;
69 }
70 else {
71 $baseHost = $jsonArr["host"];
72 if (!is_string($baseHost)) {
73 throw new AuthInfoLoadException("Optional field \"host\" must be a string");
74 }
75
76 $api = "api-$baseHost";
77 $content = "api-content-$baseHost";
78 $web = "meta-$baseHost";
79
80 $host = new Host($api, $content, $web);
81 }
82
83 return array($accessToken, $host);
84 }
85 }
86