Skip to content

Commit dcd48f9

Browse files
committed
update file structure and ecrecover module
1 parent 812dc3c commit dcd48f9

File tree

147 files changed

+578
-15205
lines changed

Some content is hidden

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

147 files changed

+578
-15205
lines changed

.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; https://editorconfig.org/
2+
3+
root = true
4+
5+
[*]
6+
indent_style = space
7+
indent_size = 4
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
end_of_line = lf
11+
charset = utf-8
12+
13+
[*.{json,yml}]
14+
indent_size = 2
15+
16+
[*.neon]
17+
indent_style = tab
18+
19+
[Makefile]
20+
indent_style = tab

.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Ignore build files
2+
build/*
3+
4+
# Mac OS X dumps these all over the place.
5+
.DS_Store
6+
7+
# Ignore the SimpleTest library if it is installed to /test/.
8+
/test/simpletest/
9+
10+
# Ignore the /vendor/ directory for people using composer
11+
/vendor/
12+
13+
# If the vendor directory isn't being commited the composer.lock file should also be ignored
14+
composer.lock
15+
16+
# Ignore PHPUnit coverage file
17+
clover.xml
18+
19+
# Ignore IDE's configuration files
20+
.idea
21+
22+
# Ignore PHP CS Fixer local config and cache
23+
.php_cs
24+
.php_cs.cache
25+
26+
# Ignore PHPStan local config
27+
.phpstan.neon
28+
29+
# Ignore phpDocumentor's local config and artifacts
30+
.phpdoc/*
31+
phpdoc.xml
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
MIT License
1+
The MIT License (MIT)
22

3-
Copyright (c) 2018 Boris Momčilović
3+
Copyright (c) 2020 Fortmatic 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: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require_once('vendor/autoload.php');
2424
If you do not wish to use Composer, you can download the [latest release](https://github.com/magiclabs/magic-admin-php). Then, to use the bindings, include the `magic-init.php` file.
2525

2626
```php
27-
require_once('/path/to/magic-admin-php/magic-init.php');
27+
require_once('/path/to/magic-admin-php/init.php');
2828
```
2929

3030
## Dependencies
@@ -41,36 +41,33 @@ If you use Composer, these dependencies should be handled automatically. If you
4141
Simple usage for login:
4242

4343
```php
44-
$did_token = parse_authorization_header_value(
44+
$did_token = \MagicAdmin\Util\parse_authorization_header_value(
4545
$authorization
4646
);
4747

4848
if ($did_token == null) {
49-
$badRequestError = new BadRequestError(
49+
throw new \MagicAdmin\Exception\BadRequestException(
5050
'Authorization header is missing or header value is invalid'
5151
);
52-
echo $badRequestError->getErrorMessage();
5352
}
5453

55-
$magic = new Magic('YOUR_SECRET_API_KEY');
54+
$magic = new \MagicAdmin\Magic('YOUR_SECRET_API_KEY');
5655

5756
try {
5857
$magic->token->validate($did_token);
5958
$issuer = $magic->token->get_issuer($did_token);
6059
$user_meta = $magic->user->get_metadata_by_issuer($issuer);
6160
} catch (Exception $e) {
62-
$didTokenError = new DIDTokenError(
61+
throw new \MagicAdmin\Exception\DIDTokenException(
6362
'DID Token is invalid: ' . $e->getMessage()
64-
);
65-
echo $didTokenError->getErrorMessage();
63+
);
6664
}
6765
# Call your appilication logic to load the user.
6866
/**
6967
$user_info = $logic->user->load_by($email)
7068

7169
if ($user_info->issuer != $issuer) {
72-
$unAuthorizedError = new UnAuthorizedError('UnAuthorized user login');
73-
echo $unAuthorizedError->getErrorMessage();
70+
throw new \MagicAdmin\Exception\UnAuthorizedException('UnAuthorized user login');
7471
}
7572

7673
echo $user_info;
@@ -80,28 +77,26 @@ Simple usage for login:
8077
Simple usage for logout:
8178

8279
```php
83-
$did_token = parse_authorization_header_value(
80+
$did_token = \MagicAdmin\Util\parse_authorization_header_value(
8481
$authorization
8582
);
8683

8784
if ($did_token == null) {
88-
$badRequestError = new BadRequestError(
85+
throw new \MagicAdmin\Exception\BadRequestException(
8986
'Authorization header is missing or header value is invalid'
9087
);
91-
echo $badRequestError->getErrorMessage();
9288
}
9389

94-
$magic = new Magic('YOUR_SECRET_API_KEY');
90+
$magic = new \MagicAdmin\Magic('YOUR_SECRET_API_KEY');
9591

9692
try {
9793
$magic->token->validate($did_token);
9894
$issuer = $magic->token->get_issuer($did_token);
9995
$user_meta = $magic->user->get_metadata_by_issuer($issuer);
10096
} catch (Exception $e) {
101-
$didTokenError = new DIDTokenError(
97+
throw new \MagicAdmin\Exception\DIDTokenException(
10298
'DID Token is invalid: ' . $e->getMessage()
103-
);
104-
echo $didTokenError->getErrorMessage();
99+
);
105100
}
106101

107102

@@ -110,8 +105,7 @@ Simple usage for logout:
110105
$user_info = $logic->user->load_by($email)
111106

112107
if ($user_info->issuer != $issuer) {
113-
$unAuthorizedError = new UnAuthorizedError('UnAuthorized user login');
114-
echo $unAuthorizedError->getErrorMessage();
108+
throw new \MagicAdmin\Exception\UnAuthorizedError('UnAuthorized user login');
115109
}
116110
**/
117111
```

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0.0

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66
"admin",
77
"link"
88
],
9-
"homepage": "https://magic.link/",
9+
"homepage": "https://magic.link",
1010
"license": "MIT",
1111
"authors": [
1212
{
13-
"name": "",
14-
"homepage": ""
13+
"name": "Wanjiu Jin",
14+
"email": "[email protected]"
1515
}
1616
],
1717
"require": {
1818
"php": ">=5.6.0",
1919
"ext-curl": "*",
20-
"ext-gmt": "*"
20+
"ext-gmp": "*",
21+
"digitaldonkey/ecverify": "^1.0"
2122
},
2223
"autoload": {
2324
"psr-4": {

config.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

init.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
// Magic
4+
require( __dir__ . '/lib/Magic.php' );
5+
6+
// Resources
7+
require( __dir__ . '/lib/Resource/Token.php' );
8+
require( __dir__ . '/lib/Resource/User.php' );
9+
10+
// HttpClient
11+
require( __dir__ . '/lib/HttpClient.php' );
12+
13+
// Response
14+
require( __dir__ . '/lib/Response.php' );
15+
16+
// Utilities
17+
require( __dir__ . '/lib/Util/DidToken.php' );
18+
require( __dir__ . '/lib/Util/Http.php' );
19+
require( __dir__ . '/lib/Util/Time.php' );
20+
21+
// Exceptions
22+
require( __dir__ . '/lib/Exception/MagicException.php' );
23+
require( __dir__ . '/lib/Exception/DidTokenException.php' );
24+
require( __dir__ . '/lib/Exception/ApiConnectionException.php' );
25+
require( __dir__ . '/lib/Exception/RequestException.php' );
26+
require( __dir__ . '/lib/Exception/RateLimitException.php' );
27+
require( __dir__ . '/lib/Exception/BadRequestException.php' );
28+
require( __dir__ . '/lib/Exception/AuthenticationException.php' );
29+
require( __dir__ . '/lib/Exception/ForbiddenException.php' );
30+
require( __dir__ . '/lib/Exception/ApiException.php' );
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace MagicAdmin\Exception;
4+
5+
/**
6+
* ApiConnectionException is thrown in the event that
7+
* the SDK can't connect to Magic's servers.
8+
*/
9+
10+
class ApiConnectionException extends MagicException {}

lib/Exception/ApiException.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace MagicAdmin\Exception;
4+
5+
/**
6+
* Other api request exception
7+
*/
8+
9+
class ApiException extends RequestException {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace MagicAdmin\Exception;
4+
5+
/**
6+
* AuthenticationException is thrown in the event that
7+
* the API secret key is missing.
8+
*/
9+
10+
class AuthenticationException extends RequestException {}

lib/Exception/BadRequestException.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace MagicAdmin\Exception;
4+
5+
/**
6+
* BadRequestException is thrown in the event that
7+
* authorization header is missing or header value is invalid.
8+
*/
9+
10+
class BadRequestException extends RequestException {}
11+
12+
13+

lib/Exception/DidTokenException.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace MagicAdmin\Exception;
4+
5+
/**
6+
* DIDTokenException is thrown in the event that DID token is missing,
7+
* DID token is malformed, given DID token has expired or
8+
* signature mismatch between "proof" and "claim".
9+
*/
10+
11+
class DIDTokenException extends MagicException {}

lib/Exception/ForbiddenException.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace MagicAdmin\Exception;
4+
5+
/**
6+
* ForbiddenException is thrown in the event that
7+
* the SDK request is not allowed to access to server.
8+
*/
9+
10+
class ForbiddenException extends RequestException {}
11+
12+
13+

lib/Exception/MagicException.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace MagicAdmin\Exception;
4+
5+
/**
6+
* Magic custom exception
7+
*/
8+
9+
class MagicException extends \Exception {
10+
11+
public $_message = "";
12+
13+
public function __construct($message=null) {
14+
parent::__construct($message);
15+
$this->_message = $message;
16+
}
17+
18+
public function getErrorMessage() {
19+
return $this->_message;
20+
}
21+
22+
public function getRepr() {
23+
return __class__ . '(message=' . $this->_message . ')';
24+
}
25+
}

lib/Exception/RateLimitException.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace MagicAdmin\Exception;
4+
5+
/**
6+
* RateLimitException is thrown in the event that
7+
* the SDK has sent too many requests to server in a given amount of time.
8+
*/
9+
10+
class RateLimitException extends RequestException {}

0 commit comments

Comments
 (0)