-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathOAuthTests.php
More file actions
92 lines (73 loc) · 2.83 KB
/
OAuthTests.php
File metadata and controls
92 lines (73 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
namespace DocuSign\eSign\Test;
use DocuSign\eSign\Client\ApiClient;
use PHPUnit\Framework\TestCase;
/**
* User: Naveen Gopala
* Date: 1/25/16
* Time: 4:58 PM
*/
class OAuthTests extends TestCase
{
/**
* scope string to apply
*
* @var null
*/
private $scope = null;
protected function setUp(): void
{
$testConfig = new TestConfig();
$testConfig->setApiClient(new ApiClient());
$this->config = $testConfig;
$oAuth = $this->config->getApiClient()->getOAuth();
$oAuth->setBasePath($testConfig->getHost());
$this->scope = [
ApiClient::$SCOPE_SIGNATURE,
ApiClient::$SCOPE_IMPERSONATION
];
}
public function testOauthUri()
{
$uri = $this->config->getApiClient()->getAuthorizationURI($this->config->getIntegratorKey(), $this->scope, $this->config->getReturnUrl(), 'code');
self::assertStringEndsWith($this->config->getReturnUrl(), $uri);
echo $uri;
}
public function testJwtUser()
{
$token = $this->config->getApiClient()->requestJWTUserToken($this->config->getIntegratorKey(), $this->config->getUserId(), $this->config->getClientKey(), $this->scope);
self::assertInstanceOf('DocuSign\eSign\Client\Auth\OAuthToken', $token[0]);
}
public function testJwtApplication()
{
$token = $this->config->getApiClient()->requestJWTApplicationToken($this->config->getIntegratorKey(), $this->config->getClientKey(), $this->scope);
self::assertInstanceOf('DocuSign\eSign\Client\Auth\OAuthToken', $token[0]);
}
/**
* @depends testOauthUri
*/
public function testAuthorizationCodeLogin()
{
# Use printed URL to navigate through browser for authentication
# IMPORTANT: after the login, DocuSign will send back a fresh
# # authorization code as a query param of the redirect URI.
# # You should set up a route that handles the redirect call to get
# # that code and pass it to token endpoint as shown in the next
# # lines:
# #
# $code = '';
# $token = $this->config->getApiClient()->generateAccessToken($this->config->getIntegratorKey(), $this->config->getClientSecret(), $code);
# self::assertInstanceOf('DocuSign\eSign\Client\Auth\OAuthToken', $token[0]);
# echo $token[0];
# $user = $this->config->getApiClient()->getUserInfo($token[0]['access_token']);
# self::assertInstanceOf('DocuSign\eSign\Client\Auth\UserInfo', $user[0]);
# self::assertSame(200, $user[1]);
# $loginAccount = $user[0]['accounts'][0];
# if (isset($loginInformation)) {
# $accountId = $loginAccount->getAccountId();
# if (!empty($accountId)) {
# $this->config->setAccountId($accountId);
# }
# }
}
}