|
7 | 7 | * 1. generate Self-Signed SSL Certificate
|
8 | 8 | * - generate a private key: openssl genrsa -out private.key 2048
|
9 | 9 | * - generate a public key: openssl req -new -x509 -key private.key -out publickey.cer -days 365
|
10 |
| - * 2. upload the publickey.cer to your app in the Azure portal |
11 |
| - * 3. note the displayed thumbprint for the certificate |
12 |
| - * 4. initialize ClientContext instance and pass thumbprint and the contents of private.key |
| 10 | + * 2. upload the publickey.cer to your app in the Azure portal and note the displayed thumbprint for the certificate |
| 11 | + * 3. initialize ClientContext instance and pass thumbprint and the contents of private.key |
13 | 12 | * along with tenantName and clientId into withClientCertificate method
|
14 | 13 | *
|
15 | 14 | * Documentation: https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azuread
|
|
18 | 17 | require_once __DIR__ . '/../vendor/autoload.php';
|
19 | 18 | $settings = include(__DIR__ . './../../tests/Settings.php');
|
20 | 19 |
|
21 |
| -use Office365\Runtime\Auth\ClientCredential; |
22 | 20 | use Office365\SharePoint\ClientContext;
|
23 | 21 |
|
24 |
| -try { |
25 | 22 |
|
26 |
| - $thumbprint = "054343442AC255DD07488910C7E000F92227FD98"; |
27 |
| - $privateKey = file_get_contents("./private.key"); |
| 23 | +$thumbprint = "054343442AC255DD07488910C7E000F92227FD98"; |
| 24 | +$privateKey = file_get_contents("./private.key"); |
28 | 25 |
|
29 |
| - $credentials = new ClientCredential($settings['ClientId'], $settings['ClientSecret']); |
30 |
| - $ctx = (new ClientContext($settings['Url']))->withClientCertificate( |
31 |
| - $settings['TenantName'], $settings['ClientId'], $privateKey, $thumbprint); |
| 26 | +$ctx = (new ClientContext($settings['Url']))->withClientCertificate( |
| 27 | + $settings['TenantName'], $settings['ClientId'], $privateKey, $thumbprint); |
32 | 28 |
|
33 |
| - $whoami = $ctx->getWeb()->getCurrentUser()->get()->executeQuery(); |
34 |
| - print $whoami->getLoginName(); |
35 |
| -} |
36 |
| -catch (Exception $e) { |
37 |
| - echo 'Authentication failed: ', $e->getMessage(), "\n"; |
38 |
| -} |
| 29 | +//$whoami = $ctx->getWeb()->getCurrentUser()->get()->executeQuery(); |
| 30 | +//print $whoami->getLoginName(); |
| 31 | +$web = $ctx->getWeb()->get()->executeQuery(); |
| 32 | +print $web->getUrl(); |
0 commit comments