refactor: use CraftTable naming in OAuth client
This commit is contained in:
Vendored
+4
-4
@@ -505,7 +505,7 @@ var OAuthCallbackServer = class {
|
||||
|
||||
// src/oauthProvider.ts
|
||||
import { randomBytes, timingSafeEqual } from "node:crypto";
|
||||
var GameCraftOAuthProvider = class {
|
||||
var CraftTableOAuthProvider = class {
|
||||
constructor(options, tokenStore, discoveryStore, onRedirect, state = randomBytes(32).toString("base64url")) {
|
||||
this.options = options;
|
||||
this.tokenStore = tokenStore;
|
||||
@@ -577,7 +577,7 @@ var GameCraftOAuthProvider = class {
|
||||
async function connectRemote(options, tokenStore, discoveryStore, serviceToken = process.env.CRAFTTABLE_MCP_TOKEN?.trim()) {
|
||||
const tokens = await tokenStore.get(credentialAccount(options));
|
||||
if (tokens) {
|
||||
const provider = new GameCraftOAuthProvider(options, tokenStore, discoveryStore, () => {
|
||||
const provider = new CraftTableOAuthProvider(options, tokenStore, discoveryStore, () => {
|
||||
throw new Error("OAuth login is required; run `crafttable-mcp login`");
|
||||
});
|
||||
return connectWithTransport(options, new StreamableHTTPClientTransport(options.url, { authProvider: provider }), "oauth");
|
||||
@@ -594,7 +594,7 @@ async function loginRemote(options, tokenStore, discoveryStore, input = { browse
|
||||
`));
|
||||
await requireOAuthProtectedResourceMetadata(options.url);
|
||||
let authorizationUrl;
|
||||
const provider = new GameCraftOAuthProvider(options, tokenStore, discoveryStore, async (url) => {
|
||||
const provider = new CraftTableOAuthProvider(options, tokenStore, discoveryStore, async (url) => {
|
||||
authorizationUrl = url;
|
||||
if (!input.browser) {
|
||||
writeLine(`Open this URL to log in:
|
||||
@@ -603,7 +603,7 @@ ${url.toString()}`);
|
||||
}
|
||||
try {
|
||||
await open(url.toString(), { wait: false });
|
||||
writeLine("Opened the system browser for Game-CraftTable login.");
|
||||
writeLine("Opened the system browser for CraftTable login.");
|
||||
} catch (error) {
|
||||
writeLine(`Could not open the browser (${errorMessage(error)}). Open this URL manually:
|
||||
${url.toString()}`);
|
||||
|
||||
Vendored
+2
-2
File diff suppressed because one or more lines are too long
@@ -5,7 +5,7 @@ import type { ClientOptions } from "./config.js";
|
||||
import { credentialAccount, DiscoveryStore, OAUTH_SCOPES } from "./config.js";
|
||||
import type { TokenStore } from "./credentials.js";
|
||||
|
||||
export class GameCraftOAuthProvider implements OAuthClientProvider {
|
||||
export class CraftTableOAuthProvider implements OAuthClientProvider {
|
||||
readonly redirectUrl: URL;
|
||||
readonly clientMetadata: OAuthClientMetadata;
|
||||
private readonly account: string;
|
||||
|
||||
+4
-4
@@ -7,7 +7,7 @@ import { OAuthCallbackServer } from "./callbackServer.js";
|
||||
import type { ClientOptions } from "./config.js";
|
||||
import { credentialAccount, DiscoveryStore, errorMessage } from "./config.js";
|
||||
import type { TokenStore } from "./credentials.js";
|
||||
import { GameCraftOAuthProvider } from "./oauthProvider.js";
|
||||
import { CraftTableOAuthProvider } from "./oauthProvider.js";
|
||||
|
||||
export type RemoteConnection = {
|
||||
client: Client;
|
||||
@@ -24,7 +24,7 @@ export async function connectRemote(
|
||||
): Promise<RemoteConnection> {
|
||||
const tokens = await tokenStore.get(credentialAccount(options));
|
||||
if (tokens) {
|
||||
const provider = new GameCraftOAuthProvider(options, tokenStore, discoveryStore, () => {
|
||||
const provider = new CraftTableOAuthProvider(options, tokenStore, discoveryStore, () => {
|
||||
throw new Error("OAuth login is required; run `crafttable-mcp login`");
|
||||
});
|
||||
return connectWithTransport(options, new StreamableHTTPClientTransport(options.url, { authProvider: provider }), "oauth");
|
||||
@@ -46,7 +46,7 @@ export async function loginRemote(
|
||||
const writeLine = input.writeLine ?? ((value) => process.stderr.write(`${value}\n`));
|
||||
await requireOAuthProtectedResourceMetadata(options.url);
|
||||
let authorizationUrl: URL | undefined;
|
||||
const provider = new GameCraftOAuthProvider(options, tokenStore, discoveryStore, async (url) => {
|
||||
const provider = new CraftTableOAuthProvider(options, tokenStore, discoveryStore, async (url) => {
|
||||
authorizationUrl = url;
|
||||
if (!input.browser) {
|
||||
writeLine(`Open this URL to log in:\n${url.toString()}`);
|
||||
@@ -54,7 +54,7 @@ export async function loginRemote(
|
||||
}
|
||||
try {
|
||||
await open(url.toString(), { wait: false });
|
||||
writeLine("Opened the system browser for Game-CraftTable login.");
|
||||
writeLine("Opened the system browser for CraftTable login.");
|
||||
} catch (error) {
|
||||
writeLine(`Could not open the browser (${errorMessage(error)}). Open this URL manually:\n${url.toString()}`);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { OAuthTokens } from "@modelcontextprotocol/sdk/shared/auth.js";
|
||||
import { OAuthCallbackServer } from "../src/callbackServer.js";
|
||||
import { credentialAccount, resolveClientOptions, validateMcpUrl } from "../src/config.js";
|
||||
import type { TokenStore } from "../src/credentials.js";
|
||||
import { GameCraftOAuthProvider } from "../src/oauthProvider.js";
|
||||
import { CraftTableOAuthProvider } from "../src/oauthProvider.js";
|
||||
import { logoutRemote, requireOAuthProtectedResourceMetadata } from "../src/remote.js";
|
||||
|
||||
class MemoryTokens implements TokenStore {
|
||||
@@ -38,7 +38,7 @@ test("OAuth provider validates state and replaces rotated refresh tokens", async
|
||||
const options = resolveClientOptions({ url: "https://example.test/mcp", clientId: "client", callbackPort: 48321, env: {} });
|
||||
const tokens = new MemoryTokens();
|
||||
const discovery = new MemoryDiscovery();
|
||||
const provider = new GameCraftOAuthProvider(options, tokens, discovery as never, () => undefined, "expected-state");
|
||||
const provider = new CraftTableOAuthProvider(options, tokens, discovery as never, () => undefined, "expected-state");
|
||||
assert.equal(provider.validateState("expected-state"), true);
|
||||
assert.equal(provider.validateState("wrong-state"), false);
|
||||
provider.saveCodeVerifier("verifier");
|
||||
|
||||
Reference in New Issue
Block a user