import React, { useMemo, useState } from "react"; import { buildAuthDenyCallbackUrl, formatOAuthRedirectLabel, formatWebsiteLabel } from "../config"; import icons from "../icons"; import { MailtoEmail } from "./common"; import AvatarImg from "./AvatarImg"; const DEFAULT_PERMISSIONS = [ { title: "账户标识", desc: "获取账户名(account),用于在该应用中唯一识别你的萌芽身份。" }, { title: "基本资料", desc: "获取昵称、头像、邮箱、等级、萌芽币、个人主页与简介等(以「验证令牌」「当前用户」等接口实际返回为准)。" }, { title: "访问令牌", desc: "向你选择的应用颁发 JWT;应用仅在令牌有效期内、经你同意后代表你请求萌芽账户认证中心接口,不会获得你的登录密码。" }, { title: "应用接入记录", desc: "在「应用接入」中记录该应用的 client_id 与名称,便于你在用户中心查看已与哪些应用建立关联。" } ]; function scopeLabel(s) { const lower = String(s || "").toLowerCase().trim(); const map = { openid: "OpenID(账户标识)", profile: "个人资料(昵称、头像等展示信息)", email: "邮箱地址", offline_access: "离线访问(延长令牌有效期的扩展能力,若应用支持)" }; return map[lower] || s; } export default function OAuthConsentScreen({ authFlow, user, onAllow, onSwitchAccount, onPreviewImage }) { const [permsOpen, setPermsOpen] = useState(true); const appLabel = useMemo(() => { const name = (authFlow?.clientName || "").trim(); const id = (authFlow?.clientId || "").trim(); if (name) return name; if (id) return id; return "第三方应用"; }, [authFlow]); const redirectLabel = formatOAuthRedirectLabel(authFlow?.redirectUri); const redirectUrl = (authFlow?.redirectUri || "").trim(); const extraScopes = useMemo(() => { const raw = authFlow?.scopes || []; if (!raw.length) return []; return raw.map(scopeLabel); }, [authFlow]); const handleDeny = () => { const url = buildAuthDenyCallbackUrl(authFlow?.redirectUri, authFlow?.state || ""); if (url) window.location.replace(url); }; return (

{appLabel}

请求访问你的萌芽统一账户

{user?.username || user?.account || "用户"}
@{user?.account} 的身份授权
{user?.email ? (
{user.email}
) : (
未绑定邮箱
)}
应用信息
将获取以下信息与权限
{permsOpen && ( )}

点击「允许」后,你将返回应用 {formatWebsiteLabel(redirectUrl) || redirectLabel},并在浏览器地址的 Hash 中携带访问令牌。

); }