MsGraph Admin

Only administrators can login as tenants.

A routes example:

Route::group(['middleware' => ['web', 'auth']], function(){
    Route::get('msgraph', function(){

        if (! is_string(MsGraphAdmin::getAccessToken())) {
            return redirect(env('MSGRAPH_OAUTH_URL'));
        } else {
            //display all users
            return MsGraphAdmin::get('users');
        }

    });

    Route::get('msgraph/oauth', function(){
        return MsGraphAdmin::connect();
    });
});

Or using a middleware route, if user does not have a graph token then automatically redirect to get authenticated:

Route::group(['middleware' => ['web', 'MsGraphAdminAuthenticated']], function(){
    Route::get('msgraph', function(){
        //fetch all users
        return MsGraphAdmin::get('users');
    });
});

Route::get('msgraph/oauth', function(){
    return MsGraphAdmin::connect();
});

Once authenticated you can call MsGraph:: with the following verbs:

MsGraphAdmin::get($endpoint, $array = [])
MsGraphAdmin::post($endpoint, $array = [])
MsGraphAdmin::put($endpoint, $array = [])
MsGraphAdmin::patch($endpoint, $array = [])
MsGraphAdmin::delete($endpoint, $array = [])

The second param is array is not always required, its requirement is determined from the endpoint being called, see the API documentation for more details.

These expect the API endpoints to be passed, the url https://graph.microsoft.com/beta/ is provided, only endpoints after this should be used ie:

MsGraphAdmin::get('users')

 

Support my work by donating with PayPal.

Subscribe to my newsletter

Subscribe and get my books and product announcements.

© 2009 - 2021 DC Blog. All code MIT license. All rights reserved.