Skip to content

Commit d1fa31f

Browse files
Merge pull request #2 from Setasign/async-workflow
Added async-demo
2 parents e8f51a4 + 1d4dce7 commit d1fa31f

File tree

10 files changed

+551
-227
lines changed

10 files changed

+551
-227
lines changed

.idea/misc.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 26 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ Electronic Seals to digital sign PDF documents in pure PHP.
77
The API documentation can be found on the Cloud Signature Consortium website:
88
https://cloudsignatureconsortium.org/resources/download-api-specifications/
99

10-
At writing time the module is tested with the eSigner CSC API from SSL.com.
10+
At the time of writing the module is tested with the eSigner CSC API from SSL.com and the Remote Signing Service CSC API from Entrust.
1111
It currently does not support all features or variances that may appear in other API implementations.
12-
You can follow this integration guide to get a better understanding of how to setup a test environment and how the
13-
signature workflow works:
14-
https://www.ssl.com/guide/integration-guide-testing-remote-signing-with-esigner-csc-api/
1512

16-
We implemented the same workflow in this module but instead of using postman you can use the module directly and
17-
sign your PDF documents locally.
13+
For usage with SSL.com you can follow this integration guide to get a better understanding of how to setup a test
14+
environment and how the signature workflow works:
15+
https://www.ssl.com/guide/integration-guide-testing-remote-signing-with-esigner-csc-api/
16+
(instead of using postman you can use this module directly and sign your PDF documents locally).
1817

1918
## Known not implemented features
2019

@@ -95,70 +94,34 @@ This class is a kind of proxy class to the CSC API. Its constructor requires the
9594

9695
If you need to call an endpoint which is not covered by a proxy method, you can use the `call(string $path, ?string $accessToken = null, array $inputData = [])` method.
9796

98-
### The `Module` class
97+
### How do I get an access token?
9998

100-
This is the main signature module which can be used with the [SetaPDF-Signer](https://www.setasign.com/signer)
101-
component. It's constructor requires the following arguments:
99+
An access token is returned by an authorization to the API service.
102100

103-
- `$accessToken` The access token
104-
- `$client` A `Client` instance - see above
101+
This was tested only by an OAuth2 authorization yet. You can to use an OAuth2 implementation such as
102+
[league/oauth2-client](https://github.com/thephpleague/oauth2-client).
103+
Sample code for this can be found in "[examples/generate-token.php](examples/generate-token.php)".
105104

106-
### How do I get an access token?
105+
### Authorization modes
107106

108-
An access token is returned by an authorization to the API service.
107+
Accessing a credential for remote signing requires an authorization from the user who owns it to control the signing
108+
key associated to it.
109109

110-
This was tested only by an OAuth2 authorization yet. You can to use an OAuth2 implementation such as
110+
The CSC API supports multiple authorization modes. The authorization mode also defines whether the signing process must
111+
be asynchronous or not. To get this information you can call `Client::credentialsInfo()` and in the key "authMode" you'll
112+
find one of the following authorization modes:
113+
114+
- implicit: the authorization process is managed by the remote service autonomously. Authentication factors are managed by the remote signing service provider by interacting directly with the user, and not by the signature application.
115+
- explicit: the authorization process is managed by the signature application, which collects authentication factors like PIN or One-Time Passwords (OTP).
116+
- oauth2code: the authorization process is managed by the remote service using an OAuth 2.0 mechanism based on authorization code.
117+
118+
For both "implicit" and "explicit" you can use the synchronous process (see [examples/demo.php](examples/demo.php) and [examples/ltv-demo.php](examples/ltv-demo.php)).
119+
120+
For "oauth2code" you must use the asynchronous process (see [examples/demo-async.php](examples/async-demo.php)). This
121+
will require an oauth2 implementation such as
111122
[league/oauth2-client](https://github.com/thephpleague/oauth2-client).
112-
Sample code for this can be found in "[examples/generate-token.php](examples/generate-token.php)".
113123

114-
### Demo
115-
116-
A simple complete signature process would look like this:
117-
118-
```php
119-
$accessToken = '...COMES E.G. FROM THE OAUTH2 AUTHORIZATION...';
120-
$otp = '123456'; // one-time-password
121-
122-
$httpClient = new GuzzleHttp\Client();
123-
// if you are using php 7.0 or 7.1
124-
//$httpClient = new Mjelamanov\GuzzlePsr18\Client($httpClient);
125-
$requestFactory = new Http\Factory\Guzzle\RequestFactory();
126-
$streamFactory = new Http\Factory\Guzzle\StreamFactory();
127-
128-
$client = new Client($apiUri, $httpClient, $requestFactory, $streamFactory);
129-
130-
$credentialIds = ($client->credentialsList($accessToken)['credentialIds']);
131-
// we just use the first credential on the list
132-
$credentialId = $credentialIds[0];
133-
// fetch all informations regarding your credential id like the certificates
134-
$credentialInfo = $client->credentialsInfo($accessToken, $credentialId, 'chain', true, true);
135-
// get the certificate chain
136-
$certificates = $credentialInfo['cert']['certificates'];
137-
// the first certificate is always the signing certificate
138-
$certificate = array_shift($certificates);
139-
$algorithm = $credentialInfo['key']['algo'][0];
140-
141-
$module = new setasign\SetaPDF\Signer\Module\CSC\Module(
142-
$accessToken,
143-
$client
144-
);
145-
$module->setSignatureAlgorithmOid($algorithm);
146-
$module->setCertificate($certificate);
147-
$module->setExtraCertificates($certificates);
148-
$module->setOtp($otp);
149-
150-
// the file to sign
151-
$fileToSign = __DIR__ . '/assets/Laboratory-Report.pdf';
152-
153-
// create a writer instance
154-
$writer = new SetaPDF_Core_Writer_File('signed.pdf');
155-
// create the document instance
156-
$document = SetaPDF_Core_Document::loadByFilename($fileToSign, $writer);
157-
158-
// create the signer instance
159-
$signer = new SetaPDF_Signer($document);
160-
$signer->sign($module);
161-
```
124+
More about the authorization modes can be found in "8.2 Credential authorization" of the CSC API.
162125

163126
## License
164127

examples/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/settings.php
2-
/signed.pdf
2+
/signed.pdf
3+
/private

0 commit comments

Comments
 (0)