Forum Discussion
Getting User based bearer token
shakila_jayarathne you can't, the OAuth model doesn't allow you to interact with the API without providing valid credentials. A client ID and secret would be used for an app connecting to the service on behalf of the browsing user. Can I ask what you are trying to achieve?
- shakila_jayarathneAug 06, 2020Copper Contributor
I'm trying to call this "https://graph.microsoft.com/v1.0/me/onlineMeetings" api. To call this, i need user based bearer token.
Here is reference "https://docs.microsoft.com/en-us/graph/api/application-post-onlinemeetings?view=graph-rest-1.0&tabs=http"
Here is what i try
private string AddOnlineMeeting(string accessToken,string meetingName)
{string webUrl = string.Empty;
try
{
var data = new
{
startDateTime = "2020-07-13T14:30:34.2444915-07:00",
endDateTime = "2020-07-14T14:30:34.2444915-07:00",
subject = meetingName
};var serializer = new JavaScriptSerializer();
var json = serializer.Serialize(data);WebRequest createGroupRequest = WebRequest.Create("https://graph.microsoft.com/v1.0/me/onlineMeetings");
createGroupRequest.Method = "POST";
createGroupRequest.ContentType = "application/json";
createGroupRequest.Headers.Add("Authorization", "Bearer " + accessToken);
byte[] byteArray = Encoding.UTF8.GetBytes(json);
createGroupRequest.ContentLength = byteArray.Length;
Stream dataStream = createGroupRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();using (WebResponse response = createGroupRequest.GetResponse())
{
string jsonR = string.Empty;
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
jsonR = reader.ReadToEnd();
}CreateMeetingResponse meetingRes = JsonConvert.DeserializeObject<CreateMeetingResponse>(jsonR);
webUrl = meetingRes.joinWebUrl;
}
}
catch(Exception ex)
{}
return webUrl;
}- MrCoupsAug 06, 2020Copper Contributor
shakila_jayarathne have you looked at the following page?https://docs.microsoft.com/en-us/graph/auth-v2-user
This explains the authentication flow for you and the calls you need to make to obtain a token.