aminghadersohi commented on code in PR #37973: URL: https://github.com/apache/superset/pull/37973#discussion_r2806881931
########## superset-frontend/src/features/apiKeys/ApiKeyCreateModal.tsx: ########## @@ -0,0 +1,150 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { useState } from 'react'; +import { SupersetClient, t } from '@superset-ui/core'; +import { css, useTheme, Alert } from '@apache-superset/core/ui'; +import { + FormModal, + FormItem, + Input, + Button, +} from '@superset-ui/core/components'; +import { useToasts } from 'src/components/MessageToasts/withToasts'; + +interface ApiKeyCreateModalProps { + show: boolean; + onHide: () => void; + onSuccess: () => void; +} + +interface FormValues { + name: string; +} + +export function ApiKeyCreateModal({ + show, + onHide, + onSuccess, +}: ApiKeyCreateModalProps) { + const theme = useTheme(); + const { addDangerToast, addSuccessToast } = useToasts(); + const [createdKey, setCreatedKey] = useState<string | null>(null); + const [copied, setCopied] = useState(false); + + const handleFormSubmit = async (values: FormValues) => { + try { + const response = await SupersetClient.post({ + endpoint: '/api/v1/security/api_keys/', + jsonPayload: values, + }); + setCreatedKey(response.json.result.key); + addSuccessToast(t('API key created successfully')); + } catch (error) { + addDangerToast(t('Failed to create API key')); + } + }; + + const handleCopyKey = () => { + if (createdKey) { + navigator.clipboard.writeText(createdKey); + setCopied(true); + setTimeout(() => setCopied(false), 2000); Review Comment: Good catch — the clipboard write is async and should be awaited with error handling. Fixed in d65327189a: `handleCopyKey` is now `async`, awaits the clipboard write, and shows a danger toast on failure instead of silently swallowing the rejected promise. ########## superset/mcp_service/auth.py: ########## @@ -107,14 +116,28 @@ def get_user_from_request() -> User: if hasattr(g, "user") and g.user: return g.user + # Try API key authentication via FAB SecurityManager + api_key_enabled = current_app.config.get("FAB_API_KEY_ENABLED", False) + if api_key_enabled: Review Comment: Valid point — when MCP tools run with only an application context (no HTTP request), `_extract_api_key_from_request()` would hit a RuntimeError trying to access `flask.request`. Fixed in d65327189a by guarding with `has_request_context()` so API key auth is only attempted when there's an actual HTTP request. ########## requirements/base.txt: ########## @@ -120,7 +120,7 @@ flask==2.3.3 # flask-session # flask-sqlalchemy # flask-wtf -flask-appbuilder==5.0.2 +flask-appbuilder @ git+https://github.com/aminghadersohi/Flask-AppBuilder@amin/ch99414/api-key-auth Review Comment: Acknowledged — this is a temporary pin to the FAB feature branch during development. Once the FAB PR (https://github.com/dpgaspar/Flask-AppBuilder/pull/2431) is merged and released to PyPI, this will be reverted to a standard version pin (e.g., `flask-appbuilder>=5.2.0`). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
