PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label microsoft-graph-api. Show all posts
Showing posts with label microsoft-graph-api. Show all posts

Tuesday, June 28, 2022

[FIXED] How to specify search option with MS graph java SDK

 June 28, 2022     graph, microsoft-graph-api, msgraph, outlook-graph-api     No comments   

Issue

IMessageCollectionRequest eventRequest = graphClient.getGraphClient().users(user.getEmail()).messages()
                .buildRequest(new HeaderOption("Prefer", "outlook.body-content-type=\"text\""))
                .select("body,subject,toRecipients,ccRecipients,CreatedDateTime,conversationId,from");

IMessageCollectionPage eventPage = eventRequest
                                  .filter(filter)
                                  .get();

In the above code I am able to get results based on specified filter.

Now I want below search to be performed insteat of filter as MS graph does not support both of these to be applied.

https://graph.microsoft.com/v1.0/users/{{UserId}}/messages?$search="recipients:@xyz.com" & $top=1000

How can we specify search condition instead of filter. exactly shown in the above URL usig java SDK.


Solution

You can specify options in buildRequest.

LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new QueryOption("$search", "\"recipients:@xyz.com\""));

MessageCollectionPage messages = graphClient.users("{UserId}").messages()
    .buildRequest( requestOptions )
    .top(1000)
    .get();


Answered By - user2250152
Answer Checked By - Willingham (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] how to schedule recurring Teams channel meetings in Teams Calendar by Using API

 June 28, 2022     graph, microsoft-graph-api, microsoft-graph-teams, microsoft-teams     No comments   

Issue

I am trying to create a scheduled meeting in the teams channel by using API, I haven't found any API for that, Please provide me that API


Solution

Please go through event resource type to Create an event in the user's default calendar or specified calendar. You can use recurrence property to set the recurrence pattern for the event.

Update : Currently API to create event in team channel is not available.



Answered By - Meghana-MSFT
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to pass # character for the $filter to Microsoft Graph?

 June 28, 2022     active-directory, azure-active-directory, graph, microsoft-graph-api, postman     No comments   

Issue

I try to filter the following user using Microsoft Graph by userPrincipalName:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users",
    "value": [
        {
            "businessPhones": [],
            "displayName": "Champi Non Buen Dia",
            "givenName": "buendiachampi",
            "jobTitle": null,
            "mail": "champinon.buendia@champi.com",
            "mobilePhone": null,
            "officeLocation": null,
            "preferredLanguage": null,
            "surname": "urrutia",
            "userPrincipalName": "champinon.buendia_champi.com#EXT#@avtestonline.onmicrosoft.com",
            "id": "c6d071ee-5d89-49bb-ac23-768720e5eff4"
        }
    ]
}

When I request with the following URL I get the above JSON result:

https://graph.microsoft.com/v1.0/users?$filter=startswith(userPrincipalName,'champinon.buendia_champi.com')

, but if I add to the filter #EXT# I get a bad request result, how can I pass that character in the filter value?

https://graph.microsoft.com/v1.0/users?$filter=startswith(userPrincipalName,'champinon.buendia_champi.com#EXT#')

The reason why I need to do as is, is that the user must be forced to enter the full username and not a part of it, that #EXT# makes the filtering more accurate, because the username entered in must match with the #EXT#.


Solution

The value of #EXT# must be passed encoded as %23EXT%23:

https://graph.microsoft.com/v1.0/users?$filter=startswith(userPrincipalName,'edgardo.urrutia_tcs.com%23EXT%23@')


Answered By - Sabila2022
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, March 8, 2022

[FIXED] How can I get the current user's picture from Microsoft Graph in this Laravel app?

 March 08, 2022     laravel, microsoft-graph-api, php     No comments   

Issue

I am working on a Laravel 8 app that uses Microsoft Azure for user management (login included).

I began by following this tutorial on their website.

I got stuck trying to display the current user's picture.

In the view I have:

<img src="{{ isset($user_avatar) ? $user_avatar : asset('img/default-avatar.png') }}" class="rounded-circle avatar-top">

In the AuthController controller I get the current user with the data:

$user = $graph->createRequest('GET', '/me? 
$select=displayName,mail,mailboxSettings,userPrincipalName,givenName,surname,photo')
      ->setReturnType(Model\User::class)
      ->execute();

In the app\Http\Controllers\Controller.php I have:

class Controller extends BaseController {
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
        
    public function loadViewData() {

        $viewData = [];

        // Check for flash errors
        if (session('error')) {
            $viewData['error'] = session('error');
            $viewData['errorDetail'] = session('errorDetail');
        }

        // Check for logged on user
        if (session('userName'))
        {
            $viewData['userName'] = session('userName');
            $viewData['firstName'] = session('firstName');
            $viewData['lastName'] = session('lastName');
            $viewData['user_avatar'] = session('userAvatar');
            $viewData['userEmail'] = session('userEmail');
            $viewData['userTimeZone'] = session('userTimeZone');
        }

        return $viewData;
    }
}

In the DashboardContoller, I pass $viewData to the view:

class DashboardContoller extends Controller
{
    public function index(){
        $viewData = $this->loadViewData();
        return view('dashboard', $viewData);
    }
}

In app\TokenStore\TokenCache.php I have:

public function storeTokens($accessToken, $user) {
 session([
  'accessToken' => $accessToken->getToken(),
  'refreshToken' => $accessToken->getRefreshToken(),
  'tokenExpires' => $accessToken->getExpires(),
  'userName' => $user->getDisplayName(),
  'firstName' => $user->getGivenName(),
  'lastName' => $user->getSurname(),
  // Set AVATAR
  'userAvatar' => $user->getPhoto(),
  'userEmail' => null !== $user->getMail() ? $user->getMail() : $user->getUserPrincipalName(),
  'userTimeZone' => $user->getMailboxSettings()->getTimeZone()
 ]);
}

As can be seen above, I use the getPhoto() method present in the User model (vendor\microsoft\microsoft-graph\src\Model\User.php).

I successfully displayed the user's full name this way.

The problem:

For a reason I have been unable to figure out, the user_avatar returns null.

What is my mistake?


Solution

It's known issue that Photo property on User resource type is always null. Graph API doesn't support using Select with the Photo property at the moment.

To get the content of photo you have to call another endpoint

GET /me/photo/$value
GET /users/{id | userPrincipalName}/photo/$value

Add to AuthController

$photo = $graph->createRequest("GET", "/me/photo/\$value")
       ->execute();
$photoMeta = $graph->createRequest("GET", "/me/photo")
       ->execute();

Update storeTokens function for userAvatar

public function storeTokens($accessToken, $user, $photo, $photoMeta) {
 $body = $photo->getRawBody();
 $base64 = base64_encode($body);
 $meta = $photoMeta->getBody();
 $mime = $meta["@odata.mediaContentType"]
 $img = ('data:' . $mime . ';base64,' . $base64);
 session([
  'accessToken' => $accessToken->getToken(),
  'refreshToken' => $accessToken->getRefreshToken(),
  'tokenExpires' => $accessToken->getExpires(),
  'userName' => $user->getDisplayName(),
  'firstName' => $user->getGivenName(),
  'lastName' => $user->getSurname(),
  // Set AVATAR
  'userAvatar' => $img,
  'userEmail' => null !== $user->getMail() ? $user->getMail() : $user->getUserPrincipalName(),
  'userTimeZone' => $user->getMailboxSettings()->getTimeZone()
 ]);
}

Resources:

Get profilePhoto

How to include photo

Graph API support for Photos property in select



Answered By - user2250152
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing