You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Examples.md
+50-15Lines changed: 50 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,39 +23,74 @@ $graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
23
23
24
24
```
25
25
26
-
To make requests on behalf of an already signed in user, where your front-end application has already acquired an access token for the user, you can use the `OnBehalfOfContext` which uses the [On-Behalf-Of flow](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow) to fetch
27
-
an access token for your backend application to access the Microsoft Graph API. To do this, you pass the already acquired access token as the "assertion";
26
+
To make requests without a signed-in user (using application permissions), you can initialise a `ClientCredentialsContext` object:
28
27
29
28
```php
30
29
use Microsoft\Graph\GraphServiceClient;
31
-
use Microsoft\Kiota\Authentication\Oauth\OnBehalfOfContext;
30
+
use Microsoft\Kiota\Authentication\Oauth\ClientCredentialContext;
32
31
33
-
$tokenRequestContext = new OnBehalfOfContext(
32
+
// Uses https://graph.microsoft.com/.default scopes if none are specified
33
+
$tokenRequestContext = new ClientCredentialContext(
34
34
'tenantId',
35
35
'clientId',
36
-
'clientSecret',
37
-
'assertion'
36
+
'clientSecret'
38
37
);
39
-
40
-
$scopes = ['User.Read', 'Mail.ReadWrite'];
41
-
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
38
+
$graphServiceClient = new GraphServiceClient($tokenRequestContext);
42
39
43
40
```
44
41
42
+
To make requests on behalf of a signed in user, you can use the `OnBehalfOfContext` which uses the [On-Behalf-Of flow](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow) to fetch
43
+
an access token for your backend application to access the Microsoft Graph API.
45
44
46
-
To make requests without a signed-in user (using application permissions), you can initialise a `ClientCredentialsContext` object:
45
+
This is useful when you would like your user to log in once and have your application do some background work
46
+
on behalf of the user without asking them to log in again.
47
+
48
+
See the following guides on how to expose an API using your application registration:
For future token requests, pass the previously acquired access token as the `assertion` and the Microsoft Identity platform will return an access token valid for accessing Microsoft Graph data;
47
80
48
81
```php
49
82
use Microsoft\Graph\GraphServiceClient;
50
-
use Microsoft\Kiota\Authentication\Oauth\ClientCredentialContext;
83
+
use Microsoft\Kiota\Authentication\Oauth\OnBehalfOfContext;
51
84
52
-
// Uses https://graph.microsoft.com/.default scopes if none are specified
53
-
$tokenRequestContext = new ClientCredentialContext(
85
+
$tokenRequestContext = new OnBehalfOfContext(
54
86
'tenantId',
55
87
'clientId',
56
-
'clientSecret'
88
+
'clientSecret',
89
+
'assertion'
57
90
);
58
-
$graphServiceClient = new GraphServiceClient($tokenRequestContext);
91
+
92
+
$scopes = ['User.Read', 'Mail.ReadWrite'];
93
+
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
0 commit comments