-
Notifications
You must be signed in to change notification settings - Fork 145
Description
As for Client Credential provider Flow , Azure Application level 'Calendar.readWrite' permission is required which is not permissible in my company because I will get permissions of read write calendar of other employees. Is there another way from which I can write auth flow with delegated permissions and use these fields (isonlineMeeting,onlineMeetingProvider) to create MS Teams Meeting??
I am using MS Graph Event Class/APIs, MS Graph Java SDK.
This is my code:
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import com.microsoft.graph.auth.confidentialClient.AuthorizationCodeProvider;
import com.microsoft.graph.auth.confidentialClient.ClientCredentialProvider;
import com.microsoft.graph.auth.enums.NationalCloud;
import com.microsoft.graph.auth.publicClient.UsernamePasswordProvider;
import com.microsoft.graph.models.extensions.Attendee;
import com.microsoft.graph.models.extensions.DateTimeTimeZone;
import com.microsoft.graph.models.extensions.EmailAddress;
import com.microsoft.graph.models.extensions.Event;
import com.microsoft.graph.models.extensions.IGraphServiceClient;
import com.microsoft.graph.models.extensions.ItemBody;
import com.microsoft.graph.models.extensions.Location;
import com.microsoft.graph.models.generated.AttendeeType;
import com.microsoft.graph.models.generated.BodyType;
import com.microsoft.graph.models.generated.OnlineMeetingProviderType;
import com.microsoft.graph.options.HeaderOption;
import com.microsoft.graph.options.Option;
import com.microsoft.graph.requests.extensions.GraphServiceClient;
public class MSGraphPOC2 {
static List SCOPES = Arrays.asList("Calendars.ReadWrite");
//static List SCOPES =Arrays.asList("https://graph.microsoft.com/.default");
// static AuthorizationCodeProvider authProvider = new AuthorizationCodeProvider("377688fb-31a1-4bb4-b3b4-c1de056692d6",
// SCOPES, authCode,"https://TestAADApp",NationalCloud.Global,"7a746742-7931-4f5d-8af3-d2bf6fbb3a15",clientSecret);
static ClientCredentialProvider authProvider = new ClientCredentialProvider("client Id", SCOPES,clientSecret,"tenant id",NationalCloud.Global);
static IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
public static void main(String[] args) {
MSGraphPOC2.createMeting();
}
public static void createMeting() {
LinkedList requestOptions = new LinkedList();
//requestOptions.add(new HeaderOption("Prefer", "outlook.timezone="Pacific Standard Time""));
requestOptions.add(new HeaderOption("Prefer", "outlook.timezone="Pacific Standard Time""));
Event event = new Event();
event.subject = "Testing4";
ItemBody body = new ItemBody();
body.contentType = BodyType.HTML;
body.content = "Testing Muli factor autherntication";
event.body = body;
DateTimeTimeZone start = new DateTimeTimeZone();
start.dateTime = "2020-08-16T12:00:00";
start.timeZone = "Pacific Standard Time";
event.start = start;
DateTimeTimeZone end = new DateTimeTimeZone();
end.dateTime = "2020-08-16T14:00:00";
end.timeZone = "Pacific Standard Time";
event.end = end;
Location location = new Location();
location.displayName = "Testing room";
event.location = location;
LinkedList attendeesList = new LinkedList();
Attendee attendee1 = new Attendee();
EmailAddress emailAddres1 = new EmailAddress();
emailAddres1.address = "Jagriti.Pandey@mind-infotech.com";
emailAddres1.name = "Jagriti Pandey";
attendee1.emailAddress = emailAddres1;
attendee1.type = AttendeeType.REQUIRED;
/Attendee attendee2 = new Attendee();
EmailAddress emailAddres2 = new EmailAddress();
emailAddres2.address = "gaurav.sharma@mind-infotech.com";
emailAddres2.name = "Gaurav Sharma";
attendee2.emailAddress = emailAddres2;
attendee2.type = AttendeeType.REQUIRED;/
attendeesList.add(attendee1);
//attendeesList.add(attendee2);
event.attendees = attendeesList;
event.isOnlineMeeting = true;
event.onlineMeetingProvider = OnlineMeetingProviderType.TEAMS_FOR_BUSINESS;
/* graphClient.me().events()
.buildRequest( requestOptions )
.post(event);*/
Event eventResp=graphClient.me().events().buildRequest( requestOptions ).post(event);
}
}