Skip to content

Instantly share code, notes, and snippets.

View isvargasmsft's full-sized avatar

Isaac Vargas isvargasmsft

  • Microsoft
  • San Jose, Costa Rica
View GitHub Profile
@isvargasmsft
isvargasmsft / request2.php
Last active July 10, 2023 21:11
Fluent experience in the 2.0 SDK
<?php
// v1.x
$response = $graphClient->createRequest('GET', '/users/userId/messages')
->setReturnType(Model\User::class)
->execute();
// v2.0.0
$response = $graphServiceClient->users()->byUserId('userId')->messages()->get()->wait();
@isvargasmsft
isvargasmsft / request.php
Last active July 10, 2023 21:11
Request builder pattern for PHP SDK 2.0.0-RC5
<?php
// v1.x
$response = $graphClient->createRequest('GET', '/users/userId/messages')
->setReturnType(Model\User::class)
->execute();
// v2.0-RC
$response = $graphServiceClient->usersById('userId')->messages()->get()->wait();
@isvargasmsft
isvargasmsft / auth.php
Last active July 10, 2023 21:12
Auth example for PHP SDK 2.0.0-RC5
<?php
// v1.x
$accessToken = getAccessToken(); // custom token retrieval method
$graph = new Graph();
$graph->setAccessToken($accessToken);
$graph ->createRequest('GET', '/me')
->setAccessToken(getAccessToken()) //after initial token expires
...
@isvargasmsft
isvargasmsft / init_rc19.php
Created July 10, 2023 21:17
Initialization in RC19 vs RC5
<?php
//RC5 initialization experience
$tokenRequestContext = new ClientCredentialContext(
'tenantID',
'clientID',
'clientSecret'
);
$scopes = ['https://graph.microsoft.com/.default'];
$authProvider = new PhpLeagueAuthenticationProvider($tokenRequestContext, $scopes);
@isvargasmsft
isvargasmsft / requestpattern_rc19.php
Created July 10, 2023 21:25
Request builder in RC19 vs RC5
<?php
//RC5
$response = $graphServiceClient->usersById('userID')->get();
//RC19
$response = $graphServiceClient->users()->byUserId('userId')->get();
@isvargasmsft
isvargasmsft / composer.json
Created July 10, 2023 21:40
Upgrade to a new RC version
{
"name": "isvargasmsft/phpdemoapp",
"description": "This is an app for demos",
"authors": [
{
"name": "y"
}
],
"minimum-stability": "RC",
"require": {
@isvargasmsft
isvargasmsft / app-only.php
Created October 10, 2023 17:23
PHP simple initialization
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Kiota\Abstractions\ApiException;
use Microsoft\Kiota\Authentication\Oauth\ClientCredentialContext;
set_include_path(__DIR__);
require 'vendor/autoload.php';
$tokenRequestContext = new ClientCredentialContext(
'tenantID',
@isvargasmsft
isvargasmsft / app-only.py
Created October 12, 2023 16:03
Python simple initialization
import asyncio
from azure.identity.aio import ClientSecretCredential
from msgraph import GraphServiceClient
credential = ClientSecretCredential(
'tenant_id',
'client_id',
'client_secret'
)
scopes = ['https://graph.microsoft.com/.default']
@isvargasmsft
isvargasmsft / auth.py
Last active October 12, 2023 16:48
Auth example for Python SDK
# Example using async credentials and application access.
from azure.identity.aio import ClientSecretCredential
from msgraph import GraphServiceClient
credential = ClientSecretCredential(
'TENANT_ID',
'CLIENT_ID',
'CLIENT_SECRET',
)
scopes = ['https://graph.microsoft.com/.default']
@isvargasmsft
isvargasmsft / request.py
Last active October 12, 2023 16:49
Request builder pattern for Python SDK
client = GraphServiceClient(credentials=credential, scopes=scopes)
# GET /users/{id | userPrincipalName}
async def get_user():
user = await client.users.by_user_id('userPrincipalName').get()