Skip to content

Commit 14365b5

Browse files
committed
magic admin php update and adding tests
1 parent b32eff5 commit 14365b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1040
-805
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ root = true
44

55
[*]
66
indent_style = space
7-
indent_size = 4
7+
indent_size = 2
88
insert_final_newline = true
99
trim_trailing_whitespace = true
1010
end_of_line = lf

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2020 Fortmatic Inc.
3+
Copyright (c) 2020 Magic Labs Inc.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,27 @@ If you use Composer, these dependencies should be handled automatically. If you
4141
Simple usage for login:
4242

4343
```php
44-
$did_token = \MagicAdmin\Util\parse_authorization_header_value(
45-
$authorization
46-
);
47-
48-
if ($did_token == null) {
49-
throw new \MagicAdmin\Exception\BadRequestException(
50-
'Authorization header is missing or header value is invalid'
51-
);
52-
}
44+
$did_token = \MagicAdmin\Util\parse_authorization_header_value(
45+
$authorization
46+
);
5347

54-
$magic = new \MagicAdmin\Magic('YOUR_SECRET_API_KEY');
55-
56-
try {
57-
$magic->token->validate($did_token);
58-
$issuer = $magic->token->get_issuer($did_token);
59-
$user_meta = $magic->user->get_metadata_by_issuer($issuer);
60-
} catch (Exception $e) {
61-
throw new \MagicAdmin\Exception\DIDTokenException(
62-
'DID Token is invalid: ' . $e->getMessage()
63-
);
64-
}
48+
if ($did_token == null) {
49+
throw new \MagicAdmin\Exception\BadRequestException(
50+
'Authorization header is missing or header value is invalid'
51+
);
52+
}
53+
54+
$magic = new \MagicAdmin\Magic('YOUR_SECRET_API_KEY');
55+
56+
try {
57+
$magic->token->validate($did_token);
58+
$issuer = $magic->token->get_issuer($did_token);
59+
$user_meta = $magic->user->get_metadata_by_issuer($issuer);
60+
} catch (Exception $e) {
61+
throw new \MagicAdmin\Exception\DIDTokenException(
62+
'DID Token is invalid: ' . $e->getMessage()
63+
);
64+
}
6565
# Call your appilication logic to load the user.
6666
/**
6767
$user_info = $logic->user->load_by($email)
@@ -72,41 +72,41 @@ Simple usage for login:
7272

7373
echo $user_info;
7474
**/
75-
```
75+
```
7676

7777
Simple usage for logout:
7878

7979
```php
80-
$did_token = \MagicAdmin\Util\parse_authorization_header_value(
81-
$authorization
80+
$did_token = \MagicAdmin\Util\parse_authorization_header_value(
81+
$authorization
82+
);
83+
84+
if ($did_token == null) {
85+
throw new \MagicAdmin\Exception\BadRequestException(
86+
'Authorization header is missing or header value is invalid'
8287
);
88+
}
8389

84-
if ($did_token == null) {
85-
throw new \MagicAdmin\Exception\BadRequestException(
86-
'Authorization header is missing or header value is invalid'
87-
);
88-
}
90+
$magic = new \MagicAdmin\Magic('YOUR_SECRET_API_KEY');
8991

90-
$magic = new \MagicAdmin\Magic('YOUR_SECRET_API_KEY');
91-
92-
try {
93-
$magic->token->validate($did_token);
94-
$issuer = $magic->token->get_issuer($did_token);
95-
$user_meta = $magic->user->get_metadata_by_issuer($issuer);
96-
} catch (Exception $e) {
97-
throw new \MagicAdmin\Exception\DIDTokenException(
98-
'DID Token is invalid: ' . $e->getMessage()
99-
);
100-
}
92+
try {
93+
$magic->token->validate($did_token);
94+
$issuer = $magic->token->get_issuer($did_token);
95+
$user_meta = $magic->user->get_metadata_by_issuer($issuer);
96+
} catch (Exception $e) {
97+
throw new \MagicAdmin\Exception\DIDTokenException(
98+
'DID Token is invalid: ' . $e->getMessage()
99+
);
100+
}
101101

102102

103-
# Call your appilication logic to load the user.
104-
/**
105-
$user_info = $logic->user->load_by($email)
106-
107-
if ($user_info->issuer != $issuer) {
108-
throw new \MagicAdmin\Exception\UnAuthorizedError('UnAuthorized user login');
109-
}
110-
**/
103+
# Call your appilication logic to load the user.
104+
/**
105+
$user_info = $logic->user->load_by($email)
106+
107+
if ($user_info->issuer != $issuer) {
108+
throw new \MagicAdmin\Exception\UnAuthorizedError('UnAuthorized user login');
109+
}
110+
**/
111111
```
112112

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.0
1+
1.0.0

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
"ext-curl": "*",
2020
"ext-gmp": "*",
2121
"digitaldonkey/ecverify": "^1.0"
22-
},
22+
},
23+
"require-dev": {
24+
"phpunit/phpunit": "^7.3"
25+
},
2326
"autoload": {
2427
"psr-4": {
2528
"MagicAdmin\\": "/"

init.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
<?php
1+
<?php
2+
3+
// Define package root path
4+
if (!defined('MAGIC_ADMIN_PHP_PATH')) {
5+
define('MAGIC_ADMIN_PHP_PATH', __dir__);
6+
}
27

38
// Magic
49
require( __dir__ . '/lib/Magic.php' );

lib/Exception/ApiConnectionException.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77
* the SDK can't connect to Magic's servers.
88
*/
99

10-
class ApiConnectionException extends MagicException {}
11-
10+
class ApiConnectionException extends MagicException {}

lib/Exception/ApiException.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@
66
* Other api request exception
77
*/
88

9-
class ApiException extends RequestException {}
10-
9+
class ApiException extends RequestException {}

lib/Exception/AuthenticationException.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77
* the API secret key is missing.
88
*/
99

10-
class AuthenticationException extends RequestException {}
11-
10+
class AuthenticationException extends RequestException {}

lib/Exception/BadRequestException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@
77
* authorization header is missing or header value is invalid.
88
*/
99

10-
class BadRequestException extends RequestException {}
11-
12-
10+
class BadRequestException extends RequestException {}

lib/Exception/DidTokenException.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@
88
* signature mismatch between "proof" and "claim".
99
*/
1010

11-
class DIDTokenException extends MagicException {}
12-
11+
class DIDTokenException extends MagicException {}

lib/Exception/ForbiddenException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@
77
* the SDK request is not allowed to access to server.
88
*/
99

10-
class ForbiddenException extends RequestException {}
11-
12-
10+
class ForbiddenException extends RequestException {}

lib/Exception/MagicException.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,18 @@
88

99
class MagicException extends \Exception {
1010

11-
public $_message = "";
11+
public $_message = "";
1212

13-
public function __construct($message=null) {
14-
parent::__construct($message);
15-
$this->_message = $message;
16-
}
13+
public function __construct($message=null) {
14+
parent::__construct($message);
15+
$this->_message = $message;
16+
}
1717

18-
public function getErrorMessage() {
19-
return $this->_message;
20-
}
21-
22-
public function getRepr() {
23-
return __class__ . '(message=' . $this->_message . ')';
24-
}
25-
}
18+
public function getErrorMessage() {
19+
return $this->_message;
20+
}
2621

22+
public function getRepr() {
23+
return __class__ . '(message=' . $this->_message . ')';
24+
}
25+
}

lib/Exception/RateLimitException.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77
* the SDK has sent too many requests to server in a given amount of time.
88
*/
99

10-
class RateLimitException extends RequestException {}
11-
10+
class RateLimitException extends RequestException {}

lib/Exception/RequestException.php

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,41 @@
99

1010
class RequestException extends MagicException {
1111

12-
public $http_status;
13-
public $http_code;
14-
public $http_resp_data;
15-
public $http_message;
16-
public $http_error_code;
17-
public $http_request_params;
18-
public $http_request_data;
19-
public $http_method;
20-
21-
public function __construct(
22-
$message=null,
23-
$http_status=null,
24-
$http_code=null,
25-
$http_resp_data=null,
26-
$http_message=null,
27-
$http_error_code=null,
28-
$http_request_params=null,
29-
$http_request_data=null,
30-
$http_method=null
31-
) {
32-
parent::__construct($message);
33-
$this->http_status = $http_status;
34-
$this->http_code = $http_code;
35-
$this->http_resp_data = $http_resp_data;
36-
$this->http_message = $http_message;
37-
$this->http_error_code = $http_error_code;
38-
$this->http_request_params = $http_request_params;
39-
$this->http_request_data = $http_request_data;
40-
$this->http_method = $http_method;
41-
}
42-
43-
public function getRepr() {
44-
45-
return __class__ .
46-
'(message=' . $this->_message .
47-
', http_error_code=' . $this->http_error_code .
48-
', http_code=' . $this->http_code . ')';
49-
}
50-
51-
}
12+
public $http_status;
13+
public $http_code;
14+
public $http_resp_data;
15+
public $http_message;
16+
public $http_error_code;
17+
public $http_request_params;
18+
public $http_request_data;
19+
public $http_method;
20+
21+
public function __construct(
22+
$message=null,
23+
$http_status=null,
24+
$http_code=null,
25+
$http_resp_data=null,
26+
$http_message=null,
27+
$http_error_code=null,
28+
$http_request_params=null,
29+
$http_request_data=null,
30+
$http_method=null
31+
) {
32+
parent::__construct($message);
33+
$this->http_status = $http_status;
34+
$this->http_code = $http_code;
35+
$this->http_resp_data = $http_resp_data;
36+
$this->http_message = $http_message;
37+
$this->http_error_code = $http_error_code;
38+
$this->http_request_params = $http_request_params;
39+
$this->http_request_data = $http_request_data;
40+
$this->http_method = $http_method;
41+
}
42+
43+
public function getRepr() {
44+
return __class__ .
45+
'(message=' . $this->_message .
46+
', http_error_code=' . $this->http_error_code .
47+
', http_code=' . $this->http_code . ')';
48+
}
49+
}

0 commit comments

Comments
 (0)