@frustrated/ms-graph-mcp 0.1.7 → 0.1.8
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/bun.lock +1 -1
- package/package.json +1 -1
- package/src/auth.ts +18 -23
package/bun.lock
CHANGED
package/package.json
CHANGED
package/src/auth.ts
CHANGED
|
@@ -61,22 +61,10 @@ async function loadTokenCache(): Promise<boolean> {
|
|
|
61
61
|
|
|
62
62
|
export async function initAuth(): Promise<void> {
|
|
63
63
|
console.log("Initiating Microsoft Graph authentication...");
|
|
64
|
-
console.log(
|
|
65
|
-
"Please ensure you have registered a multi-tenant application in Azure AD with the following redirect URI: http://localhost:PORT/auth-callback",
|
|
66
|
-
);
|
|
67
64
|
|
|
68
65
|
const cryptoProvider = new CryptoProvider();
|
|
69
66
|
const pkceCodes = await cryptoProvider.generatePkceCodes();
|
|
70
67
|
|
|
71
|
-
const authCodeUrlParameters = {
|
|
72
|
-
scopes: SCOPES,
|
|
73
|
-
redirectUri: `http://localhost:0${REDIRECT_URI_PATH}`,
|
|
74
|
-
codeChallenge: pkceCodes.challenge,
|
|
75
|
-
codeChallengeMethod: "S256" as const,
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const authCodeUrl = await pca.getAuthCodeUrl(authCodeUrlParameters);
|
|
79
|
-
|
|
80
68
|
return new Promise((resolve, reject) => {
|
|
81
69
|
const server = createServer(async (req, res) => {
|
|
82
70
|
if (req.url?.startsWith(REDIRECT_URI_PATH)) {
|
|
@@ -86,10 +74,11 @@ export async function initAuth(): Promise<void> {
|
|
|
86
74
|
if (code) {
|
|
87
75
|
try {
|
|
88
76
|
const addr = server.address() as AddressInfo;
|
|
77
|
+
const redirectUri = `http://localhost:${addr.port}${REDIRECT_URI_PATH}`;
|
|
89
78
|
const tokenResult = await pca.acquireTokenByCode({
|
|
90
79
|
code,
|
|
91
80
|
scopes: SCOPES,
|
|
92
|
-
redirectUri
|
|
81
|
+
redirectUri,
|
|
93
82
|
codeVerifier: pkceCodes.verifier,
|
|
94
83
|
});
|
|
95
84
|
|
|
@@ -123,16 +112,22 @@ export async function initAuth(): Promise<void> {
|
|
|
123
112
|
}
|
|
124
113
|
});
|
|
125
114
|
|
|
126
|
-
server.listen(0, () => {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
115
|
+
server.listen(0, async () => {
|
|
116
|
+
try {
|
|
117
|
+
const addr = server.address() as AddressInfo;
|
|
118
|
+
const redirectUri = `http://localhost:${addr.port}${REDIRECT_URI_PATH}`;
|
|
119
|
+
const authCodeUrl = await pca.getAuthCodeUrl({
|
|
120
|
+
scopes: SCOPES,
|
|
121
|
+
redirectUri,
|
|
122
|
+
codeChallenge: pkceCodes.challenge,
|
|
123
|
+
codeChallengeMethod: "S256" as const,
|
|
124
|
+
});
|
|
125
|
+
console.log(
|
|
126
|
+
`\nOpen this URL in your browser to authenticate:\n\n ${authCodeUrl}\n`,
|
|
127
|
+
);
|
|
128
|
+
} catch (err) {
|
|
129
|
+
server.close(() => reject(err));
|
|
130
|
+
}
|
|
136
131
|
});
|
|
137
132
|
|
|
138
133
|
server.on("error", (err) => {
|