@microsoft/teamsfx-react 2.0.1-alpha.e8170e1dc.0 → 2.0.1-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -2
- package/build/cjs/index.d.ts +2 -1
- package/build/cjs/index.d.ts.map +1 -1
- package/build/cjs/index.js +4 -1
- package/build/cjs/useGraph.d.ts +15 -1
- package/build/cjs/useGraph.d.ts.map +1 -1
- package/build/cjs/useGraph.js +80 -1
- package/build/cjs/useTeamsUserCredential.d.ts +42 -0
- package/build/cjs/useTeamsUserCredential.d.ts.map +1 -0
- package/build/cjs/useTeamsUserCredential.js +34 -0
- package/build/esm/index.d.ts +2 -1
- package/build/esm/index.d.ts.map +1 -1
- package/build/esm/index.js +2 -1
- package/build/esm/useGraph.d.ts +15 -1
- package/build/esm/useGraph.d.ts.map +1 -1
- package/build/esm/useGraph.js +79 -1
- package/build/esm/useTeamsUserCredential.d.ts +42 -0
- package/build/esm/useTeamsUserCredential.d.ts.map +1 -0
- package/build/esm/useTeamsUserCredential.js +30 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -73,6 +73,27 @@ const { loading, error, data, reload } = useGraph(
|
|
|
73
73
|
);
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
+
> Note: `useGraph()` has been deprecated and will be removed in the future release. Please use `useGraphWithCredential()` instead as below:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
const { loading, error, data, reload } = useGraphWithCredential(
|
|
80
|
+
async (graph, teamsUserCredential, scope) => {
|
|
81
|
+
// Call graph api directly to get user profile information
|
|
82
|
+
const profile = await graph.api("/me").get();
|
|
83
|
+
|
|
84
|
+
let photoUrl = "";
|
|
85
|
+
try {
|
|
86
|
+
const photo = await graph.api("/me/photo/$value").get();
|
|
87
|
+
photoUrl = URL.createObjectURL(photo);
|
|
88
|
+
} catch {
|
|
89
|
+
// Could not fetch photo from user's profile, return empty string as placeholder.
|
|
90
|
+
}
|
|
91
|
+
return { profile, photoUrl };
|
|
92
|
+
},
|
|
93
|
+
{ scope: ["User.Read"] }
|
|
94
|
+
);
|
|
95
|
+
```
|
|
96
|
+
|
|
76
97
|
#### 2. Render Graph data with React
|
|
77
98
|
|
|
78
99
|
You can bind the `reload` function with a button to refresh data on demand.
|
|
@@ -106,11 +127,19 @@ If you want to manually set the initial theme, please pass the config object to
|
|
|
106
127
|
Initialize TeamsFx and Teams JS SDK, in a development environment, verbose logging message will be printed to console.
|
|
107
128
|
It returns the TeamsFx instance as data.
|
|
108
129
|
If you want to customize TeamsFx like customizing setting, please pass the config object to `useTeamsFx()`.
|
|
130
|
+
> Note: `useTeamsFx()` has been deprecated and will be removed in the future release. Please use `useTeamsUserCredential()` instead as below:
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
const authConfig: TeamsUserCredentialAuthConfig = {
|
|
134
|
+
clientId: process.env.REACT_APP_CLIENT_ID,
|
|
135
|
+
initiateLoginEndpoint: process.env.REACT_APP_START_LOGIN_PAGE_URL,
|
|
136
|
+
}
|
|
137
|
+
const { loading, theme, themeString, teamsUserCredential } = useTeamsUserCredential(authConfig);
|
|
138
|
+
```
|
|
109
139
|
|
|
110
140
|
### useGraph
|
|
111
141
|
This hook function leverage `useData` to call Graph API. It will execute the fetchGraphDataAsync function that the developer passes in first.
|
|
112
|
-
If user has not consented to the scopes of AAD resources, `useGraph()` will automatically call
|
|
113
|
-
So, developers can focus on the business logic of how to fetch Microsoft Graph data.
|
|
142
|
+
If user has not consented to the scopes of AAD resources, `useGraph()`, `useGraphWithCredential` will automatically call login function to pop up the consent dialog. So, developers can focus on the business logic of how to fetch Microsoft Graph data.
|
|
114
143
|
|
|
115
144
|
## Next steps
|
|
116
145
|
|
package/build/cjs/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { useTeams } from "./useTeams";
|
|
2
2
|
export { useData } from "./useData";
|
|
3
3
|
export { useTeamsFx, TeamsFxContext } from "./useTeamsFx";
|
|
4
|
-
export {
|
|
4
|
+
export { useTeamsUserCredential, TeamsContextWithCredential } from "./useTeamsUserCredential";
|
|
5
|
+
export { useGraph, useGraphWithCredential } from "./useGraph";
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
package/build/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAC9F,OAAO,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC"}
|
package/build/cjs/index.js
CHANGED
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
// Copyright (c) Microsoft Corporation.
|
|
3
3
|
// Licensed under the MIT license.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.useGraph = exports.useTeamsFx = exports.useData = exports.useTeams = void 0;
|
|
5
|
+
exports.useGraphWithCredential = exports.useGraph = exports.useTeamsUserCredential = exports.useTeamsFx = exports.useData = exports.useTeams = void 0;
|
|
6
6
|
var useTeams_1 = require("./useTeams");
|
|
7
7
|
Object.defineProperty(exports, "useTeams", { enumerable: true, get: function () { return useTeams_1.useTeams; } });
|
|
8
8
|
var useData_1 = require("./useData");
|
|
9
9
|
Object.defineProperty(exports, "useData", { enumerable: true, get: function () { return useData_1.useData; } });
|
|
10
10
|
var useTeamsFx_1 = require("./useTeamsFx");
|
|
11
11
|
Object.defineProperty(exports, "useTeamsFx", { enumerable: true, get: function () { return useTeamsFx_1.useTeamsFx; } });
|
|
12
|
+
var useTeamsUserCredential_1 = require("./useTeamsUserCredential");
|
|
13
|
+
Object.defineProperty(exports, "useTeamsUserCredential", { enumerable: true, get: function () { return useTeamsUserCredential_1.useTeamsUserCredential; } });
|
|
12
14
|
var useGraph_1 = require("./useGraph");
|
|
13
15
|
Object.defineProperty(exports, "useGraph", { enumerable: true, get: function () { return useGraph_1.useGraph; } });
|
|
16
|
+
Object.defineProperty(exports, "useGraphWithCredential", { enumerable: true, get: function () { return useGraph_1.useGraphWithCredential; } });
|
package/build/cjs/useGraph.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { Data } from "./useData";
|
|
2
|
-
import { TeamsFx } from "@microsoft/teamsfx";
|
|
2
|
+
import { TeamsFx, TeamsUserCredential, TeamsUserCredentialAuthConfig } from "@microsoft/teamsfx";
|
|
3
3
|
import { Client } from "@microsoft/microsoft-graph-client";
|
|
4
4
|
declare type GraphOption = {
|
|
5
5
|
scope?: string[];
|
|
6
6
|
teamsfx?: TeamsFx;
|
|
7
7
|
};
|
|
8
|
+
declare type GraphOptionWithAuthConfig = {
|
|
9
|
+
scope?: string[];
|
|
10
|
+
authConfig?: TeamsUserCredentialAuthConfig;
|
|
11
|
+
};
|
|
8
12
|
/**
|
|
9
13
|
* Helper function to call Microsoft Graph API with authentication.
|
|
10
14
|
*
|
|
@@ -15,5 +19,15 @@ declare type GraphOption = {
|
|
|
15
19
|
* @beta
|
|
16
20
|
*/
|
|
17
21
|
export declare function useGraph<T>(fetchGraphDataAsync: (graph: Client, teamsfx: TeamsFx, scope: string[]) => Promise<T>, options?: GraphOption): Data<T>;
|
|
22
|
+
/**
|
|
23
|
+
* Helper function to call Microsoft Graph API with authentication.
|
|
24
|
+
*
|
|
25
|
+
* @param fetchGraphDataAsync - async function of how to call Graph API and fetch data.
|
|
26
|
+
* @param options - Authentication configuration and OAuth resource scope.
|
|
27
|
+
* @returns data, loading status, error and reload function
|
|
28
|
+
*
|
|
29
|
+
* @beta
|
|
30
|
+
*/
|
|
31
|
+
export declare function useGraphWithCredential<T>(fetchGraphDataAsync: (graph: Client, credential: TeamsUserCredential, scope: string[]) => Promise<T>, options?: GraphOptionWithAuthConfig): Data<T>;
|
|
18
32
|
export {};
|
|
19
33
|
//# sourceMappingURL=useGraph.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGraph.d.ts","sourceRoot":"","sources":["../../src/useGraph.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAW,MAAM,WAAW,CAAC;AAC1C,OAAO,
|
|
1
|
+
{"version":3,"file":"useGraph.d.ts","sourceRoot":"","sources":["../../src/useGraph.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAW,MAAM,WAAW,CAAC;AAC1C,OAAO,EACL,OAAO,EAGP,mBAAmB,EACnB,6BAA6B,EAE9B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAc,MAAM,mCAAmC,CAAC;AAGvE,aAAK,WAAW,GAAG;IACjB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,aAAK,yBAAyB,GAAG;IAC/B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,UAAU,CAAC,EAAE,6BAA6B,CAAC;CAC5C,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,mBAAmB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,EACrF,OAAO,CAAC,EAAE,WAAW,GACpB,IAAI,CAAC,CAAC,CAAC,CAkCT;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EACtC,mBAAmB,EAAE,CACnB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,mBAAmB,EAC/B,KAAK,EAAE,MAAM,EAAE,KACZ,OAAO,CAAC,CAAC,CAAC,EACf,OAAO,CAAC,EAAE,yBAAyB,GAClC,IAAI,CAAC,CAAC,CAAC,CAmDT"}
|
package/build/cjs/useGraph.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright (c) Microsoft Corporation.
|
|
3
3
|
// Licensed under the MIT license.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.useGraph = void 0;
|
|
5
|
+
exports.useGraphWithCredential = exports.useGraph = void 0;
|
|
6
6
|
var tslib_1 = require("tslib");
|
|
7
7
|
var useData_1 = require("./useData");
|
|
8
8
|
var teamsfx_1 = require("@microsoft/teamsfx");
|
|
@@ -70,3 +70,82 @@ function useGraph(fetchGraphDataAsync, options) {
|
|
|
70
70
|
return { data: data, error: error, loading: loading, reload: reload };
|
|
71
71
|
}
|
|
72
72
|
exports.useGraph = useGraph;
|
|
73
|
+
/**
|
|
74
|
+
* Helper function to call Microsoft Graph API with authentication.
|
|
75
|
+
*
|
|
76
|
+
* @param fetchGraphDataAsync - async function of how to call Graph API and fetch data.
|
|
77
|
+
* @param options - Authentication configuration and OAuth resource scope.
|
|
78
|
+
* @returns data, loading status, error and reload function
|
|
79
|
+
*
|
|
80
|
+
* @beta
|
|
81
|
+
*/
|
|
82
|
+
function useGraphWithCredential(fetchGraphDataAsync, options) {
|
|
83
|
+
var _this = this;
|
|
84
|
+
var credential;
|
|
85
|
+
if (!(options === null || options === void 0 ? void 0 : options.authConfig)) {
|
|
86
|
+
var authConfig = {
|
|
87
|
+
clientId: process.env.REACT_APP_CLIENT_ID,
|
|
88
|
+
initiateLoginEndpoint: process.env.REACT_APP_START_LOGIN_PAGE_URL,
|
|
89
|
+
};
|
|
90
|
+
credential = new teamsfx_1.TeamsUserCredential(authConfig);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
credential = new teamsfx_1.TeamsUserCredential(options.authConfig);
|
|
94
|
+
}
|
|
95
|
+
var scope;
|
|
96
|
+
if (!(options === null || options === void 0 ? void 0 : options.scope)) {
|
|
97
|
+
scope = ["User.Read"];
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
scope = options.scope;
|
|
101
|
+
}
|
|
102
|
+
var _a = (0, react_1.useState)(false), needConsent = _a[0], setNeedConsent = _a[1];
|
|
103
|
+
var _b = (0, useData_1.useData)(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
104
|
+
var err_3, helpLink, graph, graphData, err_4;
|
|
105
|
+
var _a, _b;
|
|
106
|
+
return tslib_1.__generator(this, function (_c) {
|
|
107
|
+
switch (_c.label) {
|
|
108
|
+
case 0:
|
|
109
|
+
if (!needConsent) return [3 /*break*/, 4];
|
|
110
|
+
_c.label = 1;
|
|
111
|
+
case 1:
|
|
112
|
+
_c.trys.push([1, 3, , 4]);
|
|
113
|
+
return [4 /*yield*/, credential.login(scope)];
|
|
114
|
+
case 2:
|
|
115
|
+
_c.sent();
|
|
116
|
+
setNeedConsent(false);
|
|
117
|
+
return [3 /*break*/, 4];
|
|
118
|
+
case 3:
|
|
119
|
+
err_3 = _c.sent();
|
|
120
|
+
if (err_3 instanceof teamsfx_1.ErrorWithCode && ((_a = err_3.message) === null || _a === void 0 ? void 0 : _a.includes("CancelledByUser"))) {
|
|
121
|
+
helpLink = "https://aka.ms/teamsfx-auth-code-flow";
|
|
122
|
+
err_3.message +=
|
|
123
|
+
'\nIf you see "AADSTS50011: The reply URL specified in the request does not match the reply URLs configured for the application" ' +
|
|
124
|
+
"in the popup window, you may be using unmatched version for TeamsFx SDK (version >= 0.5.0) and Teams Toolkit (version < 3.3.0) or " +
|
|
125
|
+
"cli (version < 0.11.0). Please refer to the help link for how to fix the issue: ".concat(helpLink);
|
|
126
|
+
}
|
|
127
|
+
throw err_3;
|
|
128
|
+
case 4:
|
|
129
|
+
_c.trys.push([4, 6, , 7]);
|
|
130
|
+
graph = (0, teamsfx_1.createMicrosoftGraphClientWithCredential)(credential, scope);
|
|
131
|
+
return [4 /*yield*/, fetchGraphDataAsync(graph, credential, scope)];
|
|
132
|
+
case 5:
|
|
133
|
+
graphData = _c.sent();
|
|
134
|
+
return [2 /*return*/, graphData];
|
|
135
|
+
case 6:
|
|
136
|
+
err_4 = _c.sent();
|
|
137
|
+
if (err_4 instanceof microsoft_graph_client_1.GraphError && ((_b = err_4.code) === null || _b === void 0 ? void 0 : _b.includes("UiRequiredError"))) {
|
|
138
|
+
// Silently fail for user didn't consent error
|
|
139
|
+
setNeedConsent(true);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
throw err_4;
|
|
143
|
+
}
|
|
144
|
+
return [3 /*break*/, 7];
|
|
145
|
+
case 7: return [2 /*return*/];
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}); }), data = _b.data, error = _b.error, loading = _b.loading, reload = _b.reload;
|
|
149
|
+
return { data: data, error: error, loading: loading, reload: reload };
|
|
150
|
+
}
|
|
151
|
+
exports.useGraphWithCredential = useGraphWithCredential;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { TeamsUserCredentialAuthConfig, TeamsUserCredential } from "@microsoft/teamsfx";
|
|
2
|
+
import { ThemePrepared } from "@fluentui/react-northstar";
|
|
3
|
+
export declare type TeamsContextWithCredential = {
|
|
4
|
+
/**
|
|
5
|
+
* Instance of TeamsUserCredential.
|
|
6
|
+
*/
|
|
7
|
+
teamsUserCredential?: TeamsUserCredential;
|
|
8
|
+
/**
|
|
9
|
+
* Status of data loading.
|
|
10
|
+
*/
|
|
11
|
+
loading: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Error information.
|
|
14
|
+
*/
|
|
15
|
+
error: unknown;
|
|
16
|
+
/**
|
|
17
|
+
* Indicates that current environment is in Teams
|
|
18
|
+
*/
|
|
19
|
+
inTeams?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Teams theme.
|
|
22
|
+
*/
|
|
23
|
+
theme: ThemePrepared;
|
|
24
|
+
/**
|
|
25
|
+
* Teams theme string.
|
|
26
|
+
*/
|
|
27
|
+
themeString: string;
|
|
28
|
+
/**
|
|
29
|
+
* Teams context object.
|
|
30
|
+
*/
|
|
31
|
+
context?: any;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Initialize TeamsFx SDK with customized configuration.
|
|
35
|
+
*
|
|
36
|
+
* @param authConfig - custom configuration to override default ones.
|
|
37
|
+
* @returns TeamsContextWithCredential object
|
|
38
|
+
*
|
|
39
|
+
* @beta
|
|
40
|
+
*/
|
|
41
|
+
export declare function useTeamsUserCredential(authConfig: TeamsUserCredentialAuthConfig): TeamsContextWithCredential;
|
|
42
|
+
//# sourceMappingURL=useTeamsUserCredential.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTeamsUserCredential.d.ts","sourceRoot":"","sources":["../../src/useTeamsUserCredential.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,6BAA6B,EAC7B,mBAAmB,EACpB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAG1D,oBAAY,0BAA0B,GAAG;IACvC;;OAEG;IACH,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC;IACf;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,KAAK,EAAE,aAAa,CAAC;IACrB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IAEH,OAAO,CAAC,EAAE,GAAG,CAAC;CACf,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,6BAA6B,GACxC,0BAA0B,CAY5B"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT license.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.useTeamsUserCredential = void 0;
|
|
6
|
+
var tslib_1 = require("tslib");
|
|
7
|
+
var teamsfx_1 = require("@microsoft/teamsfx");
|
|
8
|
+
var useTeams_1 = require("./useTeams");
|
|
9
|
+
var useData_1 = require("./useData");
|
|
10
|
+
/**
|
|
11
|
+
* Initialize TeamsFx SDK with customized configuration.
|
|
12
|
+
*
|
|
13
|
+
* @param authConfig - custom configuration to override default ones.
|
|
14
|
+
* @returns TeamsContextWithCredential object
|
|
15
|
+
*
|
|
16
|
+
* @beta
|
|
17
|
+
*/
|
|
18
|
+
function useTeamsUserCredential(authConfig) {
|
|
19
|
+
var _this = this;
|
|
20
|
+
var result = (0, useTeams_1.useTeams)({})[0];
|
|
21
|
+
var _a = (0, useData_1.useData)(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
22
|
+
return tslib_1.__generator(this, function (_a) {
|
|
23
|
+
if (process.env.NODE_ENV === "development") {
|
|
24
|
+
(0, teamsfx_1.setLogLevel)(teamsfx_1.LogLevel.Verbose);
|
|
25
|
+
(0, teamsfx_1.setLogFunction)(function (level, message) {
|
|
26
|
+
console.log(message);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return [2 /*return*/, new teamsfx_1.TeamsUserCredential(authConfig)];
|
|
30
|
+
});
|
|
31
|
+
}); }), data = _a.data, error = _a.error, loading = _a.loading;
|
|
32
|
+
return tslib_1.__assign({ teamsUserCredential: data, error: error, loading: loading }, result);
|
|
33
|
+
}
|
|
34
|
+
exports.useTeamsUserCredential = useTeamsUserCredential;
|
package/build/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { useTeams } from "./useTeams";
|
|
2
2
|
export { useData } from "./useData";
|
|
3
3
|
export { useTeamsFx, TeamsFxContext } from "./useTeamsFx";
|
|
4
|
-
export {
|
|
4
|
+
export { useTeamsUserCredential, TeamsContextWithCredential } from "./useTeamsUserCredential";
|
|
5
|
+
export { useGraph, useGraphWithCredential } from "./useGraph";
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
package/build/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAC9F,OAAO,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC"}
|
package/build/esm/index.js
CHANGED
|
@@ -3,4 +3,5 @@
|
|
|
3
3
|
export { useTeams } from "./useTeams";
|
|
4
4
|
export { useData } from "./useData";
|
|
5
5
|
export { useTeamsFx } from "./useTeamsFx";
|
|
6
|
-
export {
|
|
6
|
+
export { useTeamsUserCredential } from "./useTeamsUserCredential";
|
|
7
|
+
export { useGraph, useGraphWithCredential } from "./useGraph";
|
package/build/esm/useGraph.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { Data } from "./useData";
|
|
2
|
-
import { TeamsFx } from "@microsoft/teamsfx";
|
|
2
|
+
import { TeamsFx, TeamsUserCredential, TeamsUserCredentialAuthConfig } from "@microsoft/teamsfx";
|
|
3
3
|
import { Client } from "@microsoft/microsoft-graph-client";
|
|
4
4
|
declare type GraphOption = {
|
|
5
5
|
scope?: string[];
|
|
6
6
|
teamsfx?: TeamsFx;
|
|
7
7
|
};
|
|
8
|
+
declare type GraphOptionWithAuthConfig = {
|
|
9
|
+
scope?: string[];
|
|
10
|
+
authConfig?: TeamsUserCredentialAuthConfig;
|
|
11
|
+
};
|
|
8
12
|
/**
|
|
9
13
|
* Helper function to call Microsoft Graph API with authentication.
|
|
10
14
|
*
|
|
@@ -15,5 +19,15 @@ declare type GraphOption = {
|
|
|
15
19
|
* @beta
|
|
16
20
|
*/
|
|
17
21
|
export declare function useGraph<T>(fetchGraphDataAsync: (graph: Client, teamsfx: TeamsFx, scope: string[]) => Promise<T>, options?: GraphOption): Data<T>;
|
|
22
|
+
/**
|
|
23
|
+
* Helper function to call Microsoft Graph API with authentication.
|
|
24
|
+
*
|
|
25
|
+
* @param fetchGraphDataAsync - async function of how to call Graph API and fetch data.
|
|
26
|
+
* @param options - Authentication configuration and OAuth resource scope.
|
|
27
|
+
* @returns data, loading status, error and reload function
|
|
28
|
+
*
|
|
29
|
+
* @beta
|
|
30
|
+
*/
|
|
31
|
+
export declare function useGraphWithCredential<T>(fetchGraphDataAsync: (graph: Client, credential: TeamsUserCredential, scope: string[]) => Promise<T>, options?: GraphOptionWithAuthConfig): Data<T>;
|
|
18
32
|
export {};
|
|
19
33
|
//# sourceMappingURL=useGraph.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGraph.d.ts","sourceRoot":"","sources":["../../src/useGraph.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAW,MAAM,WAAW,CAAC;AAC1C,OAAO,
|
|
1
|
+
{"version":3,"file":"useGraph.d.ts","sourceRoot":"","sources":["../../src/useGraph.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAW,MAAM,WAAW,CAAC;AAC1C,OAAO,EACL,OAAO,EAGP,mBAAmB,EACnB,6BAA6B,EAE9B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAc,MAAM,mCAAmC,CAAC;AAGvE,aAAK,WAAW,GAAG;IACjB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,aAAK,yBAAyB,GAAG;IAC/B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,UAAU,CAAC,EAAE,6BAA6B,CAAC;CAC5C,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,mBAAmB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,EACrF,OAAO,CAAC,EAAE,WAAW,GACpB,IAAI,CAAC,CAAC,CAAC,CAkCT;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EACtC,mBAAmB,EAAE,CACnB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,mBAAmB,EAC/B,KAAK,EAAE,MAAM,EAAE,KACZ,OAAO,CAAC,CAAC,CAAC,EACf,OAAO,CAAC,EAAE,yBAAyB,GAClC,IAAI,CAAC,CAAC,CAAC,CAmDT"}
|
package/build/esm/useGraph.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
3
|
import { __assign, __awaiter, __generator } from "tslib";
|
|
4
4
|
import { useData } from "./useData";
|
|
5
|
-
import { TeamsFx, createMicrosoftGraphClient, ErrorWithCode } from "@microsoft/teamsfx";
|
|
5
|
+
import { TeamsFx, createMicrosoftGraphClient, ErrorWithCode, TeamsUserCredential, createMicrosoftGraphClientWithCredential, } from "@microsoft/teamsfx";
|
|
6
6
|
import { GraphError } from "@microsoft/microsoft-graph-client";
|
|
7
7
|
import { useState } from "react";
|
|
8
8
|
/**
|
|
@@ -66,3 +66,81 @@ export function useGraph(fetchGraphDataAsync, options) {
|
|
|
66
66
|
}); }), data = _c.data, error = _c.error, loading = _c.loading, reload = _c.reload;
|
|
67
67
|
return { data: data, error: error, loading: loading, reload: reload };
|
|
68
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Helper function to call Microsoft Graph API with authentication.
|
|
71
|
+
*
|
|
72
|
+
* @param fetchGraphDataAsync - async function of how to call Graph API and fetch data.
|
|
73
|
+
* @param options - Authentication configuration and OAuth resource scope.
|
|
74
|
+
* @returns data, loading status, error and reload function
|
|
75
|
+
*
|
|
76
|
+
* @beta
|
|
77
|
+
*/
|
|
78
|
+
export function useGraphWithCredential(fetchGraphDataAsync, options) {
|
|
79
|
+
var _this = this;
|
|
80
|
+
var credential;
|
|
81
|
+
if (!(options === null || options === void 0 ? void 0 : options.authConfig)) {
|
|
82
|
+
var authConfig = {
|
|
83
|
+
clientId: process.env.REACT_APP_CLIENT_ID,
|
|
84
|
+
initiateLoginEndpoint: process.env.REACT_APP_START_LOGIN_PAGE_URL,
|
|
85
|
+
};
|
|
86
|
+
credential = new TeamsUserCredential(authConfig);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
credential = new TeamsUserCredential(options.authConfig);
|
|
90
|
+
}
|
|
91
|
+
var scope;
|
|
92
|
+
if (!(options === null || options === void 0 ? void 0 : options.scope)) {
|
|
93
|
+
scope = ["User.Read"];
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
scope = options.scope;
|
|
97
|
+
}
|
|
98
|
+
var _a = useState(false), needConsent = _a[0], setNeedConsent = _a[1];
|
|
99
|
+
var _b = useData(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
100
|
+
var err_3, helpLink, graph, graphData, err_4;
|
|
101
|
+
var _a, _b;
|
|
102
|
+
return __generator(this, function (_c) {
|
|
103
|
+
switch (_c.label) {
|
|
104
|
+
case 0:
|
|
105
|
+
if (!needConsent) return [3 /*break*/, 4];
|
|
106
|
+
_c.label = 1;
|
|
107
|
+
case 1:
|
|
108
|
+
_c.trys.push([1, 3, , 4]);
|
|
109
|
+
return [4 /*yield*/, credential.login(scope)];
|
|
110
|
+
case 2:
|
|
111
|
+
_c.sent();
|
|
112
|
+
setNeedConsent(false);
|
|
113
|
+
return [3 /*break*/, 4];
|
|
114
|
+
case 3:
|
|
115
|
+
err_3 = _c.sent();
|
|
116
|
+
if (err_3 instanceof ErrorWithCode && ((_a = err_3.message) === null || _a === void 0 ? void 0 : _a.includes("CancelledByUser"))) {
|
|
117
|
+
helpLink = "https://aka.ms/teamsfx-auth-code-flow";
|
|
118
|
+
err_3.message +=
|
|
119
|
+
'\nIf you see "AADSTS50011: The reply URL specified in the request does not match the reply URLs configured for the application" ' +
|
|
120
|
+
"in the popup window, you may be using unmatched version for TeamsFx SDK (version >= 0.5.0) and Teams Toolkit (version < 3.3.0) or " +
|
|
121
|
+
"cli (version < 0.11.0). Please refer to the help link for how to fix the issue: ".concat(helpLink);
|
|
122
|
+
}
|
|
123
|
+
throw err_3;
|
|
124
|
+
case 4:
|
|
125
|
+
_c.trys.push([4, 6, , 7]);
|
|
126
|
+
graph = createMicrosoftGraphClientWithCredential(credential, scope);
|
|
127
|
+
return [4 /*yield*/, fetchGraphDataAsync(graph, credential, scope)];
|
|
128
|
+
case 5:
|
|
129
|
+
graphData = _c.sent();
|
|
130
|
+
return [2 /*return*/, graphData];
|
|
131
|
+
case 6:
|
|
132
|
+
err_4 = _c.sent();
|
|
133
|
+
if (err_4 instanceof GraphError && ((_b = err_4.code) === null || _b === void 0 ? void 0 : _b.includes("UiRequiredError"))) {
|
|
134
|
+
// Silently fail for user didn't consent error
|
|
135
|
+
setNeedConsent(true);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
throw err_4;
|
|
139
|
+
}
|
|
140
|
+
return [3 /*break*/, 7];
|
|
141
|
+
case 7: return [2 /*return*/];
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}); }), data = _b.data, error = _b.error, loading = _b.loading, reload = _b.reload;
|
|
145
|
+
return { data: data, error: error, loading: loading, reload: reload };
|
|
146
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { TeamsUserCredentialAuthConfig, TeamsUserCredential } from "@microsoft/teamsfx";
|
|
2
|
+
import { ThemePrepared } from "@fluentui/react-northstar";
|
|
3
|
+
export declare type TeamsContextWithCredential = {
|
|
4
|
+
/**
|
|
5
|
+
* Instance of TeamsUserCredential.
|
|
6
|
+
*/
|
|
7
|
+
teamsUserCredential?: TeamsUserCredential;
|
|
8
|
+
/**
|
|
9
|
+
* Status of data loading.
|
|
10
|
+
*/
|
|
11
|
+
loading: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Error information.
|
|
14
|
+
*/
|
|
15
|
+
error: unknown;
|
|
16
|
+
/**
|
|
17
|
+
* Indicates that current environment is in Teams
|
|
18
|
+
*/
|
|
19
|
+
inTeams?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Teams theme.
|
|
22
|
+
*/
|
|
23
|
+
theme: ThemePrepared;
|
|
24
|
+
/**
|
|
25
|
+
* Teams theme string.
|
|
26
|
+
*/
|
|
27
|
+
themeString: string;
|
|
28
|
+
/**
|
|
29
|
+
* Teams context object.
|
|
30
|
+
*/
|
|
31
|
+
context?: any;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Initialize TeamsFx SDK with customized configuration.
|
|
35
|
+
*
|
|
36
|
+
* @param authConfig - custom configuration to override default ones.
|
|
37
|
+
* @returns TeamsContextWithCredential object
|
|
38
|
+
*
|
|
39
|
+
* @beta
|
|
40
|
+
*/
|
|
41
|
+
export declare function useTeamsUserCredential(authConfig: TeamsUserCredentialAuthConfig): TeamsContextWithCredential;
|
|
42
|
+
//# sourceMappingURL=useTeamsUserCredential.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTeamsUserCredential.d.ts","sourceRoot":"","sources":["../../src/useTeamsUserCredential.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,6BAA6B,EAC7B,mBAAmB,EACpB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAG1D,oBAAY,0BAA0B,GAAG;IACvC;;OAEG;IACH,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC;IACf;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,KAAK,EAAE,aAAa,CAAC;IACrB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IAEH,OAAO,CAAC,EAAE,GAAG,CAAC;CACf,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,6BAA6B,GACxC,0BAA0B,CAY5B"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
import { __assign, __awaiter, __generator } from "tslib";
|
|
4
|
+
import { LogLevel, setLogLevel, setLogFunction, TeamsUserCredential, } from "@microsoft/teamsfx";
|
|
5
|
+
import { useTeams } from "./useTeams";
|
|
6
|
+
import { useData } from "./useData";
|
|
7
|
+
/**
|
|
8
|
+
* Initialize TeamsFx SDK with customized configuration.
|
|
9
|
+
*
|
|
10
|
+
* @param authConfig - custom configuration to override default ones.
|
|
11
|
+
* @returns TeamsContextWithCredential object
|
|
12
|
+
*
|
|
13
|
+
* @beta
|
|
14
|
+
*/
|
|
15
|
+
export function useTeamsUserCredential(authConfig) {
|
|
16
|
+
var _this = this;
|
|
17
|
+
var result = useTeams({})[0];
|
|
18
|
+
var _a = useData(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
19
|
+
return __generator(this, function (_a) {
|
|
20
|
+
if (process.env.NODE_ENV === "development") {
|
|
21
|
+
setLogLevel(LogLevel.Verbose);
|
|
22
|
+
setLogFunction(function (level, message) {
|
|
23
|
+
console.log(message);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return [2 /*return*/, new TeamsUserCredential(authConfig)];
|
|
27
|
+
});
|
|
28
|
+
}); }), data = _a.data, error = _a.error, loading = _a.loading;
|
|
29
|
+
return __assign({ teamsUserCredential: data, error: error, loading: loading }, result);
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/teamsfx-react",
|
|
3
|
-
"version": "2.0.1-
|
|
3
|
+
"version": "2.0.1-rc.0",
|
|
4
4
|
"description": "React helper functions for Microsoft TeamsFx",
|
|
5
5
|
"main": "build/cjs/index.js",
|
|
6
6
|
"module": "build/esm/index.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
|
33
33
|
"@microsoft/microsoft-graph-client": "^3.0.1",
|
|
34
34
|
"@microsoft/teams-js": "^2.0.0",
|
|
35
|
-
"@microsoft/teamsfx": "2.0.1-
|
|
35
|
+
"@microsoft/teamsfx": "^2.0.1-rc.0",
|
|
36
36
|
"@testing-library/react": "^12.1.1",
|
|
37
37
|
"@testing-library/react-hooks": "^7.0.2",
|
|
38
38
|
"@types/enzyme": "^3.10.10",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"@fluentui/react-northstar": "^0.62.0",
|
|
73
73
|
"@microsoft/microsoft-graph-client": "^3.0.1",
|
|
74
74
|
"@microsoft/teams-js": "^2.0.0",
|
|
75
|
-
"@microsoft/teamsfx": "
|
|
75
|
+
"@microsoft/teamsfx": ">2.0.0-alpha",
|
|
76
76
|
"react": "^16.8.6",
|
|
77
77
|
"react-dom": "^16.8.6"
|
|
78
78
|
},
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"npx eslint --cache --fix --quiet"
|
|
85
85
|
]
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "e24cd78ce4f871c771845a1d2c9022a06ad82c3f"
|
|
88
88
|
}
|