@lynq/google 0.1.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/LICENSE +21 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.mjs +2 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 hogekai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ToolContext, ToolMiddleware, MCPServer } from '@lynq/lynq';
|
|
2
|
+
|
|
3
|
+
interface GoogleOptions {
|
|
4
|
+
/** Middleware name. Default: "google" */
|
|
5
|
+
name?: string;
|
|
6
|
+
/** Google OAuth client ID. */
|
|
7
|
+
clientId: string;
|
|
8
|
+
/** Google OAuth client secret. */
|
|
9
|
+
clientSecret: string;
|
|
10
|
+
/** OAuth callback URL (your server's callback endpoint). */
|
|
11
|
+
redirectUri: string;
|
|
12
|
+
/** OAuth scopes. Default: ["openid", "profile", "email"] */
|
|
13
|
+
scopes?: string[];
|
|
14
|
+
/** Session key for user data. Default: "user" */
|
|
15
|
+
sessionKey?: string;
|
|
16
|
+
/** Message shown to the user. Default: "Please sign in with Google to continue." */
|
|
17
|
+
message?: string;
|
|
18
|
+
/** Timeout in ms. Default: 300000 */
|
|
19
|
+
timeout?: number;
|
|
20
|
+
/** Custom skip condition. Takes priority over sessionKey check. */
|
|
21
|
+
skipIf?: (c: ToolContext) => boolean | Promise<boolean>;
|
|
22
|
+
/** Called after authentication completes successfully, before next(). */
|
|
23
|
+
onComplete?: (c: ToolContext) => void | Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
/** @deprecated Use `GoogleOptions` instead. */
|
|
26
|
+
type GoogleOAuthOptions = GoogleOptions;
|
|
27
|
+
declare function google(options: GoogleOptions): ToolMiddleware;
|
|
28
|
+
/** @deprecated Use `google()` from `@lynq/google` instead. */
|
|
29
|
+
declare const googleOAuth: typeof google;
|
|
30
|
+
interface HandleCallbackOptions {
|
|
31
|
+
clientId: string;
|
|
32
|
+
clientSecret: string;
|
|
33
|
+
redirectUri: string;
|
|
34
|
+
/** Session key for user data. Default: "user" */
|
|
35
|
+
sessionKey?: string;
|
|
36
|
+
}
|
|
37
|
+
/** @deprecated Use `HandleCallbackOptions` instead. */
|
|
38
|
+
type HandleGoogleCallbackOptions = HandleCallbackOptions;
|
|
39
|
+
/**
|
|
40
|
+
* Handle Google OAuth callback. Call from your HTTP callback route.
|
|
41
|
+
* Exchanges code for tokens, fetches user info, stores in session, and completes elicitation.
|
|
42
|
+
*/
|
|
43
|
+
declare function handleCallback(server: MCPServer, params: {
|
|
44
|
+
code: string;
|
|
45
|
+
state: string;
|
|
46
|
+
}, options: HandleCallbackOptions): Promise<{
|
|
47
|
+
success: boolean;
|
|
48
|
+
error?: string;
|
|
49
|
+
}>;
|
|
50
|
+
/** @deprecated Use `handleCallback()` from `@lynq/google` instead. */
|
|
51
|
+
declare const handleGoogleCallback: typeof handleCallback;
|
|
52
|
+
|
|
53
|
+
export { type GoogleOAuthOptions, type GoogleOptions, type HandleCallbackOptions, type HandleGoogleCallbackOptions, google, googleOAuth, handleCallback, handleGoogleCallback };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {verifyState,signState}from'@lynq/lynq/helpers';import {oauth}from'@lynq/lynq/oauth';function m(e){let s=e.scopes??["openid","profile","email"],t={name:e.name??"google",sessionKey:e.sessionKey??"user",message:e.message??"Please sign in with Google to continue.",buildUrl({sessionId:i,elicitationId:r}){return `https://accounts.google.com/o/oauth2/v2/auth?${new URLSearchParams({client_id:e.clientId,redirect_uri:e.redirectUri,response_type:"code",scope:s.join(" "),state:signState(i,r,e.clientSecret),access_type:"offline"})}`}};return e.timeout!==void 0&&(t.timeout=e.timeout),e.skipIf&&(t.skipIf=e.skipIf),e.onComplete&&(t.onComplete=e.onComplete),oauth(t)}var _=m;async function f(e,s,t){let i=t.sessionKey??"user",r=verifyState(s.state,t.clientSecret);if(!r)return {success:false,error:"Invalid state parameter"};let{sessionId:a,elicitationId:l}=r;try{let o=await(await fetch("https://oauth2.googleapis.com/token",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({code:s.code,client_id:t.clientId,client_secret:t.clientSecret,redirect_uri:t.redirectUri,grant_type:"authorization_code"})})).json();if(!o.access_token)return {success:!1,error:o.error_description??o.error??"Token exchange failed"};let d=await(await fetch("https://www.googleapis.com/oauth2/v2/userinfo",{headers:{Authorization:`Bearer ${o.access_token}`}})).json(),c=e.session(a);return c.set(i,d),c.set("accessToken",o.access_token),o.id_token&&c.set("idToken",o.id_token),e.completeElicitation(l),{success:!0}}catch(n){return {success:false,error:n instanceof Error?n.message:String(n)}}}var C=f;
|
|
2
|
+
export{m as google,_ as googleOAuth,f as handleCallback,C as handleGoogleCallback};
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lynq/google",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Google OAuth provider for lynq MCP framework.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.mjs"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@lynq/lynq": "^0.8.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"tsup": "^8.0.0",
|
|
21
|
+
"typescript": "^5.6.0",
|
|
22
|
+
"vitest": "^2.0.0",
|
|
23
|
+
"zod": "^3.24.0"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/hogekai/lynq",
|
|
31
|
+
"directory": "packages/google"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=18"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsup",
|
|
39
|
+
"test": "vitest run",
|
|
40
|
+
"typecheck": "tsc --noEmit"
|
|
41
|
+
}
|
|
42
|
+
}
|