Teams tab: Get token to call Graph (POST request)


I have a Teams tab with html/js code. I need to get an access token to call Graph API

When I send my POST request in a browser page ( I get the response:
      "token_type": "Bearer",
      "expires_in": 3599,
      "ext_expires_in": 3599,
      "access_token": "eyJ0eXA....LO40xw"

When I send a POST in my bot node js code I get the response too:

var options = {
uri: '{tenant}/oauth2/v2.0/token',
body: 'client_id=xxxx&',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
method: 'POST',

var request = require('request');
request(options, (error, response, resBody) => { console.log(JSON.stringify(body)); });



But I need to get the token from my html code (tab page). I have this code but failed:


var url = '{tenant}/oauth2/v2.0/token';
var sBody = 'client_id=xxxx&';

fetch(url, {
   method: 'POST', // *GET, POST, PUT, DELETE, etc.
   mode: 'no-cors', // no-cors, *cors, same-origin
   cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
   credentials: 'omit', // include, *same-origin, omit
   headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
   redirect: 'follow', // manual, *follow, error
   referrerPolicy: 'no-referrer', // no-referrer, *client
   body: sBody // body data type must match "Content-Type" header
   }).then(res => console.log(res))
   .then(data => console.log(data));


I get an 'opaque' response, I read about 'cors' header: "With an opaque response we won't be able to read the data returned..."


But i don't know hoy to fix it. What I tried failed...


What am I doing wrong?


Thanks in advance,


2 Replies

@diegoSpace Are you trying to do Tab authentication? Could you please try this sample out and see if you are able to get it working?

Yes, I am trying to do Tab authentication. I will try simple sample, thanks!