microsoft / BotBuilder-Samples

Welcome to the Bot Framework samples repository. Here you will find task-focused samples in C#, JavaScript/TypeScript, and Python to help you get started with the Bot Framework SDK!
https://github.com/Microsoft/botframework
MIT License
4.37k stars 4.88k forks source link

24.bot-authentication Graph calls not working in Teams #1538

Closed mplwork closed 5 years ago

mplwork commented 5 years ago

Sample information

  1. Sample type: [\samples\ or \solutions]
  2. Sample language: [dotnetcore or webapi or es6 or nodejs or typescript]
  3. Sample name:

Describe the bug

After having fixed the problems in #1537 the actual api calls to msgraph don't work. In the logs I see

(node:46152) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.

restify listening to http://undefined:undefined.

Get Bot Framework Emulator: https://aka.ms/botframework-emulator.
Running dialog with Message Activity.
Running dialog with Message Activity.

 [onTurnError]: [object Object]

This seems to be a problem with @microsoft/microsoft-graph-client but even updating it to 1.7.0 doesn't help.

I clumsily rewrote the calls in simple-graph-client.js like so:

   async getMe() {
        return await fetch(this.graphClient.api('/me').buildFullUrl(), {
           headers: {
               "Authorization": "Bearer " + this._token
           } 
           })
            .then((res)=>{
                var contentType = res.headers.get("content-type");
                if(contentType && contentType.includes("application/json")) {
                    return res.json();
                }
                throw new TypeError("Oops, we haven't got JSON!");
                })
            .then((json) => {return json;});

         }
}

and then the graph calls succeed.

To Reproduce

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

Give a clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

[bug]

stevkan commented 5 years ago

@mplwork, can you try downgrading the microsoft-graph-client npm package to v1.0.0 and try the original simple-graph-client.js code? I've had success only with that version, to date.

mplwork commented 5 years ago

@mplwork, can you try downgrading the microsoft-graph-client npm package to v1.0.0 and try the original simple-graph-client.js code? I've had success only with that version, to date.

Thanks a lot. I tried this and can confirm that v1.0.0 sort of works. It fails in getManager but everything else works.

[onTurnError]: {"statusCode":404,"code":"Request_ResourceNotFound","message":"Resource 'manager' does not exist or one of its queried reference-property objects are not present.","requestId":"2cee4a35-5394-4911-91e8-db3a5c6db0dc","date":"2019-06-03T10:52:42.000Z","body":{"code":"Request_ResourceNotFound","message":"Resource 'manager' does not exist or one of its queried reference-property objects are not present.","innerError":{"request-id":"2cee4a35-5394-4911-91e8-db3a5c6db0dc","date":"2019-06-03T10:52:42"}}}

It works if I replace getManager with this code

    async getManager() {
        return await fetch(this.graphClient.api('/me/manager')
            .version('beta')
            .select('displayName').buildFullUrl(), {
            headers:{"Authorization": "Bearer " + this._token}})
            .then((res) => {
                return res;
            });
    }

Now how de we get this fixed? Is @microsoft/microsoft-graph-client not usable for production? Should we use something else, roll our own?

stevkan commented 5 years ago

I've been in communication with the team that manages the microsoft-graph-client node package and they are aware that there are issues. As an aside, if you try v1.4.0, does that produce any positive results?

mplwork commented 5 years ago

I've been in communication with the team that manages the microsoft-graph-client node package and they are aware that there are issues. As an aside, if you try v1.4.0, does that produce any positive results?

Thanks for getting back. Yes, v1.4.0 seems to work as well.

Incidentally, the getManager function throws an error here probably because our AAD isn't set up properly. Catching the error gives

https://graph.microsoft.com/beta/me/manager?$select=displayName
{ statusCode: 404,
  code: 'Request_ResourceNotFound',
  message:
   'Resource \'manager\' does not exist or one of its queried reference-property objects are not present.',
  requestId: '4fdc072a-be28-4b90-ac48-f377e3616950',
  date: 2019-06-07T09:35:03.000Z,
  body:
   { code: 'Request_ResourceNotFound',
     message:
      'Resource \'manager\' does not exist or one of its queried reference-property objects are not present.',
     innerError:
      { 'request-id': '4fdc072a-be28-4b90-ac48-f377e3616950',
        date: '2019-06-07T09:35:03' } } }

The Graph Explorer web site gives the same answer.

stevkan commented 5 years ago

Sounds like you are setup. Glad it is working for you. Yes, that error is consistent for no manager existing in AAD.

Closing the issue as resolved. If you have any more problems related to this issue, please feel free to re-open.

EricDahlvang commented 5 years ago

Re-opening this for tracking. If the microsoft-graph-client we are using has issues, we need to update the sample to a version where it works (or remove the sample until we have it working version).

xiaolangxyz commented 5 years ago

Does it work in Emulator? I tested it. It seems not work

muhualing commented 5 years ago

image can't work either

muhualing commented 5 years ago

image it shows the same problem, and my npm package is 1.0.0 "dependencies": { "@microsoft/microsoft-graph-client": "^1.0.0",

andhdo commented 5 years ago

looks like "@microsoft/microsoft-graph-client" has changed from version 1.4.0 to current version 1.7.0, so SimpleGraphClient must be changed in order to reflect this changes or downgade the version of this librari in order to work with the current version of the example; try to remove node_nodules/@microsoft, and then modify the dependencies to: "dependencies": { "@microsoft/microsoft-graph-client": "1.4.0", then run npm install for the 24.bot-authentication example and configure all the stuff in portal.azure after that, update the .env properties and use this properties in the emulator to test

image

however i couldn't test in Teams because administrative rights.

EricDahlvang commented 5 years ago

The problem is different graph client versions are not working as expected. This PR pins a working version, and removes the call to graphClient.getManager (for parity with dotnet): https://github.com/microsoft/BotBuilder-Samples/pull/1675