To run the app locally with Graph API proxy, you can skip the user login flow and get the customized Graph API responses regardless on the permission.
- Add an option
Debug in Teams with proxy (Edge)
inRun and Debug Activity
Panel for VS Code. - Add a package script command
proxy:teamsfx
to start dev proxy. - Add folder
proxy
for dev proxy configuration. - Add the hooking code in
src/components/sample/HookForProxy.tsx
to skip the authentication flow of login/getToken for proxy mode in browser environment. - Add the hooking code in
api/getUserProfile/HookForProxy.ts
to set the proxy agent configure and set the authenticationProvider and proxy agent for Graph client
- From VS Code:
- In
.vscode/tasks.json
, add theCheck dev proxy
task to ensure thedevproxy
command available. - In
.vscode/tasks.json
, set environmentREACT_APP_HOOK_FOR_PROXY
inStart frontend with proxy
task andHOOK_FOR_PROXY
inStart backend with proxy
task to enable the hooking code. - Add the
Start dev proxy
task to start the devproxy. It leverages the package script commandproxy:teamsfx
.
- In
When the app is running, the authentication flow for login and get access token will be hooked to skip. The Graph API requests will be sent to the devproxy listening address(127.0.0.1:54000).
All the mocked Graph API responses are listed in proxy/graph-mocks.json
. To update the Please refer to how-to-mock-responses to learn more. You can See the samples in Microsoft Graph mocks from Microsoft Graph API docs and Microsoft Graph mocks from Microsoft Graph API docs with sandbox data.
To test the app with random errors from Graph API, update the package script command proxy:teamsfx
to "devproxy -p 54000 --as-system-proxy false -c proxy/graph.json -f 100 --record"
and rerun the app again.
Refer to Simulate errors to learn more.
To get the minimal permission for Graph API, launch the app by Debug in Teams with proxy (Edge)
in VS Code and test the app by calling all the Graph API requests, then switch to the Start dev proxy
task window and input S, the devproxy will print the minimal permissions in the output.
Refer to Detect minimal Microsoft Graph API permissions to learn more.
In MacOS, it may fail to run the app locally with proxy for devproxy not found even if the devproxy has already been installed. Because the Check dev proxy
and Start dev proxy
depend on the VS Code
custom tasks execution mechanism. As the default task shell is /bin/sh
for VS Code in MacOS, the PATH set by devproxy installation may not take effect for it. To make sure Check dev proxy
and Start dev proxy
can be executed successfully, you can set the PATH of devproxy in /etc/paths
or other files which can make the /bin/sh
find the devproxy.