114 lines
3.0 KiB
JavaScript
114 lines
3.0 KiB
JavaScript
export const INSERT_CLIENT = `
|
|
INSERT INTO mcp_client (client_id, client_secret, client_name, redirect_uris, grant_types, response_types, scope)
|
|
OUTPUT INSERTED.id, INSERTED.client_id, INSERTED.client_secret, INSERTED.client_name, INSERTED.redirect_uris, INSERTED.grant_types, INSERTED.response_types, INSERTED.scope, INSERTED.created_at
|
|
VALUES (@clientId, @clientSecret, @clientName, @redirectUris, @grantTypes, @responseTypes, @scope)
|
|
`;
|
|
|
|
export const GET_CLIENT = `
|
|
SELECT
|
|
id,
|
|
client_id AS clientId,
|
|
client_secret AS clientSecret,
|
|
client_name AS clientName,
|
|
redirect_uris AS redirectUris,
|
|
grant_types AS grantTypes,
|
|
response_types AS responseTypes,
|
|
scope,
|
|
created_at AS createdAt
|
|
FROM mcp_client
|
|
WHERE client_id = @clientId
|
|
`;
|
|
|
|
export const LIST_CLIENTS = `
|
|
SELECT
|
|
id,
|
|
client_id AS clientId,
|
|
client_name AS clientName,
|
|
redirect_uris AS redirectUris,
|
|
grant_types AS grantTypes,
|
|
response_types AS responseTypes,
|
|
scope,
|
|
created_at AS createdAt
|
|
FROM mcp_client
|
|
ORDER BY created_at DESC
|
|
`;
|
|
|
|
export const DELETE_CLIENT = `
|
|
DELETE FROM mcp_client
|
|
WHERE client_id = @clientId
|
|
`;
|
|
|
|
export const INSERT_AUTH_CODE = `
|
|
INSERT INTO mcp_auth_code (code, client_id, google_auth_id, redirect_uri, code_challenge, code_challenge_method, scope, expires_at)
|
|
VALUES (@code, @clientId, @googleAuthId, @redirectUri, @codeChallenge, @codeChallengeMethod, @scope, @expiresAt)
|
|
`;
|
|
|
|
export const GET_AUTH_CODE = `
|
|
SELECT
|
|
code,
|
|
client_id AS clientId,
|
|
google_auth_id AS googleAuthId,
|
|
redirect_uri AS redirectUri,
|
|
code_challenge AS codeChallenge,
|
|
code_challenge_method AS codeChallengeMethod,
|
|
scope,
|
|
expires_at AS expiresAt,
|
|
used
|
|
FROM mcp_auth_code
|
|
WHERE code = @code
|
|
`;
|
|
|
|
export const CONSUME_AUTH_CODE = `
|
|
UPDATE mcp_auth_code
|
|
SET used = 1
|
|
WHERE code = @code
|
|
`;
|
|
|
|
export const INSERT_REFRESH_TOKEN = `
|
|
INSERT INTO mcp_token (refresh_token, client_id, google_auth_id, scope, expires_at)
|
|
OUTPUT INSERTED.id
|
|
VALUES (@refreshToken, @clientId, @googleAuthId, @scope, @expiresAt)
|
|
`;
|
|
|
|
export const GET_REFRESH_TOKEN = `
|
|
SELECT
|
|
id,
|
|
refresh_token AS refreshToken,
|
|
client_id AS clientId,
|
|
google_auth_id AS googleAuthId,
|
|
scope,
|
|
expires_at AS expiresAt,
|
|
revoked
|
|
FROM mcp_token
|
|
WHERE refresh_token = @refreshToken
|
|
`;
|
|
|
|
export const REVOKE_REFRESH_TOKEN = `
|
|
UPDATE mcp_token
|
|
SET revoked = 1
|
|
WHERE refresh_token = @refreshToken
|
|
`;
|
|
|
|
export const LIST_AUTHORIZATIONS_BY_USER = `
|
|
SELECT
|
|
c.id AS clientDbId,
|
|
c.client_id AS clientId,
|
|
c.client_name AS clientName,
|
|
c.scope,
|
|
c.created_at AS clientCreatedAt,
|
|
MAX(t.created_at) AS authorizedAt,
|
|
COUNT(t.id) AS tokenCount
|
|
FROM mcp_token t
|
|
JOIN mcp_client c ON t.client_id = c.client_id
|
|
WHERE t.google_auth_id = @googleAuthId AND t.revoked = 0
|
|
GROUP BY c.id, c.client_id, c.client_name, c.scope, c.created_at
|
|
ORDER BY MAX(t.created_at) DESC
|
|
`;
|
|
|
|
export const REVOKE_USER_AUTHORIZATIONS = `
|
|
UPDATE mcp_token
|
|
SET revoked = 1
|
|
WHERE google_auth_id = @googleAuthId AND client_id = @clientId
|
|
`;
|
|
|