@crvouga/mockingbird-service-google (英语)
本地模拟器。 真正的API合同. 部分 嘲笑鸟。 。 。 .
OAuth授权,令牌交换,用户信息,RS256 OIDC发现和JWKS,令牌撤销,Gmail消息/草稿/threads/labels/历史/设置,日历发现/列表/活动/freebusy,驱动文件/上载. 通过Mockingbird的便携式抓取运行时间,并带有SQLite坚持性,命名空间,检查站,断层和管理员控制等功能.
安装
npm install @crvouga/mockingbird-service-google
使用量
import { OAuth2Client } from "google-auth-library"
import { createServer } from "@crvouga/mockingbird-service-google/server"
const google = await createServer()
// The application's OAuth client. Only its endpoints change.
const oauth = new OAuth2Client({
clientId: "client-id",
clientSecret: "client-secret",
redirectUri: "http://localhost:3000/callback",
endpoints: {
oauth2AuthBaseUrl: `${google.url}/o/oauth2/v2/auth`,
oauth2TokenUrl: `${google.url}/oauth2/token`,
},
})
const authUrl = oauth.generateAuthUrl({ scope: ["openid", "email", "profile"] })
// Test control: the seeded user approves on the consent page, as a browser would.
const consent = await fetch(`${google.url}/o/oauth2/v2/auth/callback`, {
method: "POST",
redirect: "manual",
body: new URLSearchParams({
...Object.fromEntries(new URL(authUrl).searchParams),
email: "[email protected]",
}),
})
const code = new URL(consent.headers.get("location") ?? "").searchParams.get("code") ?? ""
// The application exchanges the code and reads the profile.
const { tokens } = await oauth.getToken(code)
oauth.setCredentials(tokens)
const me = await oauth.request<{ email: string }>({ url: `${google.url}/oauth2/v2/userinfo` })
console.log(me.data.email) // "[email protected]"
await google.close()
API 密码
GoogleAPI:便携式提供者实例;接受SQLite,命名空间,时钟,定着和基底Url.createRuntime:共享运行时间,包括本地命名空间和检查站控制.GOOGLE_NAMESPACE: 默认存储名空间.document, (中文(简体) ),operationIds, (中文(简体) ),supportedOperationIds: 注册供应商路线盘点.createServer, (中文(简体) ),DEFAULT_PORT, (中文(简体) ),serveTarget从/server:回放收听器和CLI配置.
fixtures 接受合成供应商种子记录. reset() 恢复默认值。 模拟0.12.1只是一个测试神谕,从来不是一个运行时间依赖. 在Apache-2.0下移植的供应商操作员保留其许可证和归属;见LICENSE EMULATE和TIII PARTY NOTICES.md.