Descarcă Url cu tempauth aruncă eroare 403 în Microsoft grafic

voturi
0

Am fost de lucru pentru a crea un filehandler pentru a deschide fișierul în SharePoint. Am implementat OAuth pentru a autoriza aplicația.

Până acum i se poate accesa obiectul de fișier așa cum este prezentat mai jos:

{
  @odata.context:https://graph.microsoft.com/v1.0/$metadata#shares('u%21aHR0cHM6Ly9yYXBpZHBsYXRmb3JtLnNoYXJlcG9pbnQuY29tL1NoYXJlZCUyMERvY3VtZW50cy9maWxlLnRlc3Q_dGVtcGF1dGg9ZXlKMGVYQWlPaUpLVjFRaUxDSmhiR2NpT2lKdWIyNWxJbjAuZXlKaGRXUWlPaUl3TURBd01EQXdNeTB3TURBd0xUQm1aakV0WTJVd01DMHdNREF3TURBd01EQXdNREF2Y21Gd2FXUndiR0YwWm05eWJTNXphR0Z5WlhCdmFXNTBMbU52YlVBeE9XVXhNakE0WkMweU1qVm1MVFEzWVdNdE9XTXpaQzAzWXpaa00yVTVPVGxpWVdJaUxDSnBjM01pT2lJd01EQXdNREF3TXkwd01EQXdMVEJtWmpFdFkyVXdNQzB3TURBd01EQXdNREF3TURBaUxDSnVZbVlpT2lJeE5USTJNemt3TURnMElpd2laWGh3SWpvaU1UVXlOalEzTmpRNE5DSXNJbVZ1WkhCdmFXNTBkWEpzSWpvaU5IRTFlV0pCT1ZONlkyaHFaVmd3WWxKSWRFb3hjelF5YkdGYVUxRjRNRU12VVRsVlNGaG9ZVFJUVFQwaUxDSmxibVJ3YjJsdWRIVnliRXhsYm1kMGFDSTZJall6SWl3aWFYTnNiMjl3WW1GamF5STZJbFJ5ZFdVaUxDSmphV1FpT2lKYVJFa3lUVlJaTTA5WFZYUmFWRUpvV21rd01VMUVRWGRNVjFFMFRrUlJkRnB0V21wTmFsazBUVVJKZDFwVVJtMGlMQ0oyWlhJaU9pSm9ZWE5vWldSd2NtOXZablJ2YTJWdUlpd2ljMmwwWldsa0lqb2lUMWRWTTAxVVZUTk5SRUYwVFVSck1FNXBNREJaYW1NeVRGZEplVnBxUlhSUFJFazFXbFJDYlU1NlRYaFpWRmsxSWl3aWMybG5ibWx1WDNOMFlYUmxJam9pVzF3aWEyMXphVndpWFNJc0ltNWhiV1ZwWkNJNklqQWpMbVo4YldWdFltVnljMmhwY0h4aGJtbHphRUJ5WVhCcFpIQnNZWFJtYjNKdExtOXViV2xqY205emIyWjBMbU52YlNJc0ltNXBhU0k2SW0xcFkzSnZjMjltZEM1emFHRnlaWEJ2YVc1MElpd2lhWE4xYzJWeUlqb2lkSEoxWlNJc0ltTmhZMmhsYTJWNUlqb2lNR2d1Wm54dFpXMWlaWEp6YUdsd2ZERXdNRE5pWm1aa1lXRXlOV0UyT1RoQWJHbDJaUzVqYjIwaUxDSjBkQ0k2SWpBaUxDSjFjMlZRWlhKemFYTjBaVzUwUTI5dmEybGxJam9pTXlKOS5hV0U1WTFGalVYQjNUVkpMYmtWSFMzWkJXVGgxUTJGNE5IRnFTM0U1UTBscGRrNTFZMEZIY0dsd1p6MA')/driveItem/$entity,
  @microsoft.graph.downloadUrl:https://{tenant}.sharepoint.com/_layouts/15/download.aspx?UniqueId=2d7dfb93-1fae-402a-8219-0126a74d4a37&Translate=false&tempauth=eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAvcmFwaWRwbGF0Zm9ybS5zaGFyZXBvaW50LmNvbUAxOWUxMjA4ZC0yMjVmLTQ3YWMtOWMzZC03YzZkM2U5OTliYWIiLCJpc3MiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAiLCJuYmYiOiIxNTI2MzkwMDg3IiwiZXhwIjoiMTUyNjM5MzY4NyIsImVuZHBvaW50dXJsIjoiaEdpb1hmbXZjT3cveFJkMWRYNnlMV3d0dHhXSVlkeXg3UERXbmR5MFE0OD0iLCJlbmRwb2ludHVybExlbmd0aCI6IjEyNCIsImlzbG9vcGJhY2siOiJUcnVlIiwiY2lkIjoiWVdZMVlUSmhOR010WldOak15MDBaV1l4TFdJellXSXRPR1ZsWkRNM1pqZGtZekpqIiwidmVyIjoiaGFzaGVkcHJvb2Z0b2tlbiIsInNpdGVpZCI6Ik9XVTNNVFUzTURBdE1EazBOaTAwWWpjMkxXSXlaakV0T0RJNVpUQm1Oek14WVRZNSIsImFwcF9kaXNwbGF5bmFtZSI6IkJQTU4gVEVTVCIsInNpZ25pbl9zdGF0ZSI6IltcImttc2lcIl0iLCJhcHBpZCI6IjMwN2M5NmZkLTZiZTAtNDJiYi1hODNhLWE2ZDFhMGQyMTE4YiIsInRpZCI6IjE5ZTEyMDhkLTIyNWYtNDdhYy05YzNkLTdjNmQzZTk5OWJhYiIsInVwbiI6ImFuaXNoQHJhcGlkcGxhdGZvcm0ub25taWNyb3NvZnQuY29tIiwicHVpZCI6IjEwMDNCRkZEQUEyNUE2OTgiLCJzY3AiOiJhbGxwcm9maWxlcy5yZWFkIiwidHQiOiIyIiwidXNlUGVyc2lzdGVudENvb2tpZSI6bnVsbH0.aDNPQi9rWmVxSFVmemNCV3d5OUpUTTROcFd2WmxKUGdySmV4ZWxkWDU5ST0&ApiVersion=2.0,
  createdDateTime:2018-05-09T15:02:38Z,
  eTag:\{2D7DFB93-1FAE-402A-8219-0126A74D4A37},2\,
  id:01P7SZWCUT7N6S3LQ7FJAIEGIBE2TU2SRX,
  lastModifiedDateTime:2018-05-09T15:02:40Z,
  name:file.test,
  webUrl:https://{tenant}.sharepoint.com/Shared%20Documents/file.test,
  cTag:\c:{2D7DFB93-1FAE-402A-8219-0126A74D4A37},2\,
  size:13453,
  createdBy:{
    user:{
      email:[email protected]{tenant}.onmicrosoft.com,
      displayName:Anish Duwal
    }
  },
  lastModifiedBy:{
    user:{
      email:[email protected]{tenant}.onmicrosoft.com,
      displayName:Anish Duwal
    }
  },
  parentReference:{
    driveId:b!AFdxnkYJdkuy8YKeD3MaaVPyxX7gqyZNrG2Ojd27BJ6-8E-AHhORQ6Fx04pQ_BGq,
    driveType:documentLibrary,
    id:01P7SZWCV6Y2GOVW7725BZO354PWSELRRZ,
    path:/drives/b!AFdxnkYJdkuy8YKeD3MaaVPyxX7gqyZNrG2Ojd27BJ6-8E-AHhORQ6Fx04pQ_BGq/root:
  },
  file:{
    mimeType:application/octet-stream,
    hashes:{
      quickXorHash:1D02as0SaS8K4jo+JF1b5S6PUjo=
    }
  },
  fileSystemInfo:{
    createdDateTime:2018-05-09T15:02:38Z,
    lastModifiedDateTime:2018-05-09T15:02:40Z
  }
} 

Cu toate acestea primesc eroarea 403, la solicitarea conținutul utilizând @microsoft.graph.downloadUrl

Orice ajutor ar fi foarte apreciat. Mulțumiri

Actualizați Sunt folosind Express pentru a apela API-ul. Cererea de mai jos returnează răspunsul obiect de fișier așa cum este prezentat mai sus.

if(requestBody.items) {
    let [driveItem] = JSON.parse(requestBody.items);
    try {
      let content = await request.get(`${driveItem}`, {
        headers: {
          Authorization: `Bearer ${token}`,
        },
      });
      res.render('test', {content: content});
    } catch(e) {
      res.render('test', {content: e.message});
    }
  }

dar la solicitarea conținutului aruncă 403

let fileobject = JSON.parse(content);
let file = await request.get(`${fileobject[@microsoft.graph.downloadUrl]}`)

De asemenea, am încercat adăugarea de conținut la adresa URL direct, dar nu a mers prea.

if(requestBody.items) {
  let [driveItem] = JSON.parse(requestBody.items);
  try {
    let content = await request.get(`${driveItem}/content`, {
      headers: {
        Authorization: `Bearer ${token}`,
      },
    });
    res.render('test', {content: content});
  } catch(e) {
    res.render('test', {content: e.message});
  }

}

Eu folosesc aceste metode pentru a obține acces token.

async function getAccessToken(code, callback) {
  let jsonAuth = await request.post({
    url: 'https://login.microsoftonline.com/common/oauth2/token',
    formData: {
      'grant_type' : 'authorization_code',
      'code' : code,
      'client_id' : config.clientId,
      'client_secret' : config.clientSecret,
      'redirect_uri' : 'https://simpliapp.herokuapp.com/'
    }
  });
  callback(jsonAuth);
}

function getAuthorizationCode(res) {
  res.writeHead(302, {
    'Location': `https://login.microsoftonline.com/common/oauth2/authorize?response_type=code&client_id=${config.clientId}&resource=${encodeURIComponent('https://graph.microsoft.com/')}&redirect_uri=${encodeURIComponent('https://simpliapp.herokuapp.com/')}`
  });
  res.end();
}
Întrebat 15/05/2018 la 12:40
de către utilizator
În alte limbi...                            

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more