@mcp-z/oauth-microsoft 1.0.1 → 1.0.3

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.
@@ -13,6 +13,16 @@
13
13
  * 5. Handle callback, exchange code for token
14
14
  * 6. Cache token to storage
15
15
  * 7. Close ephemeral server
16
+ *
17
+ * CHANGE (2026-01-03):
18
+ * - Non-headless mode now opens the auth URL AND blocks (polls) until tokens are available,
19
+ * for BOTH redirectUri (persistent) and ephemeral (loopback) modes.
20
+ * - Ephemeral flow no longer calls `open()` itself. Instead it:
21
+ * 1) starts the loopback callback server
22
+ * 2) throws AuthRequiredError(auth_url)
23
+ * - Middleware catches AuthRequiredError(auth_url):
24
+ * - if not headless: open(url) once + poll pending state until callback completes (or timeout)
25
+ * - then retries token acquisition and injects authContext in the SAME tool call.
16
26
  */
17
27
  import { type OAuth2TokenStorageProvider } from '@mcp-z/oauth';
18
28
  import { type CachedToken, type LoopbackOAuthConfig } from '../types.js';
@@ -27,6 +37,7 @@ import { type CachedToken, type LoopbackOAuthConfig } from '../types.js';
27
37
  */
28
38
  export declare class LoopbackOAuthProvider implements OAuth2TokenStorageProvider {
29
39
  private config;
40
+ private openedStates;
30
41
  constructor(config: LoopbackOAuthConfig);
31
42
  /**
32
43
  * Get access token from Keyv using compound key
@@ -61,7 +72,73 @@ export declare class LoopbackOAuthProvider implements OAuth2TokenStorageProvider
61
72
  * @returns User's email address (mail field or userPrincipalName fallback)
62
73
  */
63
74
  private fetchUserEmailFromToken;
64
- private performEphemeralOAuthFlow;
75
+ /**
76
+ * Build Microsoft OAuth authorization URL with the "most parameters" baseline.
77
+ * This is shared by BOTH persistent (redirectUri) and ephemeral (loopback) modes.
78
+ */
79
+ private buildAuthUrl;
80
+ /**
81
+ * Create a cached token + email from an authorization code.
82
+ * This is the shared callback handler for BOTH persistent and ephemeral modes.
83
+ */
84
+ private handleAuthorizationCode;
85
+ /**
86
+ * Store token + account metadata. Shared by BOTH persistent and ephemeral modes.
87
+ */
88
+ private persistAuthResult;
89
+ /**
90
+ * Pending auth (PKCE verifier) key format.
91
+ */
92
+ private pendingKey;
93
+ /**
94
+ * Store PKCE verifier for callback (5 minute TTL).
95
+ * Shared by BOTH persistent and ephemeral modes.
96
+ */
97
+ private createPendingAuth;
98
+ /**
99
+ * Load and validate pending auth state (5 minute TTL).
100
+ * Shared by BOTH persistent and ephemeral modes.
101
+ */
102
+ private readAndValidatePendingAuth;
103
+ /**
104
+ * Mark pending auth as completed (used by middleware polling).
105
+ */
106
+ private markPendingComplete;
107
+ /**
108
+ * Clean up pending auth state.
109
+ */
110
+ private deletePendingAuth;
111
+ /**
112
+ * Wait until pending auth is marked completed (or timeout).
113
+ * Used by middleware after opening auth URL in non-headless mode.
114
+ */
115
+ private waitForOAuthCompletion;
116
+ /**
117
+ * Process an OAuth callback using shared state validation + token exchange + persistence.
118
+ * Used by BOTH:
119
+ * - ephemeral loopback server callback handler
120
+ * - persistent redirectUri callback handler
121
+ *
122
+ * IMPORTANT CHANGE:
123
+ * - We do NOT delete pending state here anymore.
124
+ * - We mark it completed so middleware can poll and then clean it up.
125
+ */
126
+ private processOAuthCallback;
127
+ /**
128
+ * Loopback OAuth server helper (RFC 8252 Section 7.3)
129
+ *
130
+ * Implements ephemeral local server with OS-assigned port (RFC 8252 Section 8.3).
131
+ * Shared callback handling uses:
132
+ * - the same authUrl builder as redirectUri mode
133
+ * - the same pending PKCE verifier storage as redirectUri mode
134
+ * - the same callback processor as redirectUri mode
135
+ */
136
+ private createOAuthCallbackServer;
137
+ /**
138
+ * Starts the ephemeral loopback server and returns an AuthRequiredError(auth_url).
139
+ * Middleware will open+poll and then retry in the same call.
140
+ */
141
+ private startEphemeralOAuthFlow;
65
142
  private exchangeCodeForToken;
66
143
  private refreshAccessToken;
67
144
  /**
@@ -13,6 +13,16 @@
13
13
  * 5. Handle callback, exchange code for token
14
14
  * 6. Cache token to storage
15
15
  * 7. Close ephemeral server
16
+ *
17
+ * CHANGE (2026-01-03):
18
+ * - Non-headless mode now opens the auth URL AND blocks (polls) until tokens are available,
19
+ * for BOTH redirectUri (persistent) and ephemeral (loopback) modes.
20
+ * - Ephemeral flow no longer calls `open()` itself. Instead it:
21
+ * 1) starts the loopback callback server
22
+ * 2) throws AuthRequiredError(auth_url)
23
+ * - Middleware catches AuthRequiredError(auth_url):
24
+ * - if not headless: open(url) once + poll pending state until callback completes (or timeout)
25
+ * - then retries token acquisition and injects authContext in the SAME tool call.
16
26
  */
17
27
  import { type OAuth2TokenStorageProvider } from '@mcp-z/oauth';
18
28
  import { type CachedToken, type LoopbackOAuthConfig } from '../types.js';
@@ -27,6 +37,7 @@ import { type CachedToken, type LoopbackOAuthConfig } from '../types.js';
27
37
  */
28
38
  export declare class LoopbackOAuthProvider implements OAuth2TokenStorageProvider {
29
39
  private config;
40
+ private openedStates;
30
41
  constructor(config: LoopbackOAuthConfig);
31
42
  /**
32
43
  * Get access token from Keyv using compound key
@@ -61,7 +72,73 @@ export declare class LoopbackOAuthProvider implements OAuth2TokenStorageProvider
61
72
  * @returns User's email address (mail field or userPrincipalName fallback)
62
73
  */
63
74
  private fetchUserEmailFromToken;
64
- private performEphemeralOAuthFlow;
75
+ /**
76
+ * Build Microsoft OAuth authorization URL with the "most parameters" baseline.
77
+ * This is shared by BOTH persistent (redirectUri) and ephemeral (loopback) modes.
78
+ */
79
+ private buildAuthUrl;
80
+ /**
81
+ * Create a cached token + email from an authorization code.
82
+ * This is the shared callback handler for BOTH persistent and ephemeral modes.
83
+ */
84
+ private handleAuthorizationCode;
85
+ /**
86
+ * Store token + account metadata. Shared by BOTH persistent and ephemeral modes.
87
+ */
88
+ private persistAuthResult;
89
+ /**
90
+ * Pending auth (PKCE verifier) key format.
91
+ */
92
+ private pendingKey;
93
+ /**
94
+ * Store PKCE verifier for callback (5 minute TTL).
95
+ * Shared by BOTH persistent and ephemeral modes.
96
+ */
97
+ private createPendingAuth;
98
+ /**
99
+ * Load and validate pending auth state (5 minute TTL).
100
+ * Shared by BOTH persistent and ephemeral modes.
101
+ */
102
+ private readAndValidatePendingAuth;
103
+ /**
104
+ * Mark pending auth as completed (used by middleware polling).
105
+ */
106
+ private markPendingComplete;
107
+ /**
108
+ * Clean up pending auth state.
109
+ */
110
+ private deletePendingAuth;
111
+ /**
112
+ * Wait until pending auth is marked completed (or timeout).
113
+ * Used by middleware after opening auth URL in non-headless mode.
114
+ */
115
+ private waitForOAuthCompletion;
116
+ /**
117
+ * Process an OAuth callback using shared state validation + token exchange + persistence.
118
+ * Used by BOTH:
119
+ * - ephemeral loopback server callback handler
120
+ * - persistent redirectUri callback handler
121
+ *
122
+ * IMPORTANT CHANGE:
123
+ * - We do NOT delete pending state here anymore.
124
+ * - We mark it completed so middleware can poll and then clean it up.
125
+ */
126
+ private processOAuthCallback;
127
+ /**
128
+ * Loopback OAuth server helper (RFC 8252 Section 7.3)
129
+ *
130
+ * Implements ephemeral local server with OS-assigned port (RFC 8252 Section 8.3).
131
+ * Shared callback handling uses:
132
+ * - the same authUrl builder as redirectUri mode
133
+ * - the same pending PKCE verifier storage as redirectUri mode
134
+ * - the same callback processor as redirectUri mode
135
+ */
136
+ private createOAuthCallbackServer;
137
+ /**
138
+ * Starts the ephemeral loopback server and returns an AuthRequiredError(auth_url).
139
+ * Middleware will open+poll and then retry in the same call.
140
+ */
141
+ private startEphemeralOAuthFlow;
65
142
  private exchangeCodeForToken;
66
143
  private refreshAccessToken;
67
144
  /**