Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
2
2020-01-17 microsoft-graph-api-mark
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Playground
2020-01-17 microsoft-graph-api-mark
Commits
bcd1cc11
Commit
bcd1cc11
authored
Jan 17, 2020
by
root
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parents
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
112 additions
and
0 deletions
+112
-0
MicrosoftGraphController.php
src/Http/Controllers/MicrosoftGraphController.php
+91
-0
MicrosoftGraphServiceProvider.php
src/MicrosoftGraphServiceProvider.php
+13
-0
web.php
src/routes/web.php
+8
-0
No files found.
src/Http/Controllers/MicrosoftGraphController.php
0 → 100644
View file @
bcd1cc11
<?php
namespace
Nexus\MicrosoftGraphApi\Http\Controllers
;
use
App\Http\Controllers\Controller
;
use
Illuminate\Http\Request
;
use
GuzzleHttp\Client
;
use
GuzzleHttp\Exception\GuzzleException
;
use
Microsoft\Graph\Exception\GraphException
;
use
Microsoft\Graph\Graph
;
use
Microsoft\Graph\Model
;
class
MicrosoftGraphController
extends
Controller
{
public
function
getOffice365Users
()
{
$tenantId
=
config
(
'app.office365_tenantId'
);
$clientId
=
config
(
'app.office365_clientId'
);
$clientSecret
=
config
(
'app.office365_clientSecret'
);
$guzzle
=
new
Client
();
$url
=
'https://login.microsoftonline.com/'
.
$tenantId
.
'/oauth2/v2.0/token'
;
$token
=
json_decode
(
$guzzle
->
post
(
$url
,
[
'form_params'
=>
[
'client_id'
=>
$clientId
,
'scope'
=>
'https://graph.microsoft.com/.default'
,
'client_secret'
=>
$clientSecret
,
'grant_type'
=>
'client_credentials'
,
],
])
->
getBody
()
->
getContents
());
$accessToken
=
$token
->
access_token
;
$headers
=
[
'Authorization'
=>
'Bearer '
.
$token
->
access_token
];
//return dd($accessToken);
// Create a Graph client
$graph
=
new
Graph
();
$graph
->
setAccessToken
(
$accessToken
);
$users
=
$graph
->
createRequest
(
'GET'
,
'/users'
)
->
setReturnType
(
Model\User
::
class
)
->
execute
();
return
dd
(
$users
);
}
public
function
getOffice365Groups
()
{
$tenantId
=
config
(
'app.office365_tenantId'
);
$clientId
=
config
(
'app.office365_clientId'
);
$clientSecret
=
config
(
'app.office365_clientSecret'
);
$guzzle
=
new
Client
();
$url
=
'https://login.microsoftonline.com/'
.
$tenantId
.
'/oauth2/v2.0/token'
;
$token
=
json_decode
(
$guzzle
->
post
(
$url
,
[
'form_params'
=>
[
'client_id'
=>
$clientId
,
'scope'
=>
'https://graph.microsoft.com/.default'
,
'client_secret'
=>
$clientSecret
,
'grant_type'
=>
'client_credentials'
,
],
])
->
getBody
()
->
getContents
());
$accessToken
=
$token
->
access_token
;
$headers
=
[
'Authorization'
=>
'Bearer '
.
$token
->
access_token
];
//return dd($accessToken);
// Create a Graph client
$graph
=
new
Graph
();
$graph
->
setAccessToken
(
$accessToken
);
$groups
=
$graph
->
createRequest
(
'GET'
,
'/groups'
)
->
setReturnType
(
Model\Group
::
class
)
->
execute
();
return
dd
(
$groups
);
}
}
src/MicrosoftGraphServiceProvider.php
0 → 100644
View file @
bcd1cc11
<?php
namespace
Nexus\MicrosoftGraphApi
;
use
Illuminate\Support\ServiceProvider
;
class
MicrosoftGraphServiceProvider
extends
ServiceProvider
{
public
function
boot
()
{
$this
->
loadRoutesFrom
(
__DIR__
.
'/routes/web.php'
);
}
public
function
register
()
{
}
}
src/routes/web.php
0 → 100644
View file @
bcd1cc11
<?php
Route
::
group
([
'namespace'
=>
'Nexus\MicrosoftGraphApi\Http\Controllers'
,
'middleware'
=>
[
'web'
]],
function
(){
Route
::
get
(
'users'
,
'MicrosoftGraphController@getOffice365Users'
);
Route
::
get
(
'groups'
,
'MicrosoftGraphController@getOffice365Groups'
);
});
?>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment