mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-25 11:20:07 +08:00
feat: support 302ai sso (#8887)
* feat: support 302.AI sso * fix: modified the name of 302.AI provider * feat: support SSO login functionality for 302.AI
This commit is contained in:
parent
18f52f2717
commit
bcb71f68c0
@ -252,7 +252,9 @@ export class WindowService {
|
||||
'https://cloud.siliconflow.cn/expensebill',
|
||||
'https://aihubmix.com/token',
|
||||
'https://aihubmix.com/topup',
|
||||
'https://aihubmix.com/statistics'
|
||||
'https://aihubmix.com/statistics',
|
||||
'https://dash.302.ai/sso/login',
|
||||
'https://dash.302.ai/charge'
|
||||
]
|
||||
|
||||
if (oauthProviderUrls.some((link) => url.startsWith(link))) {
|
||||
|
||||
@ -1,6 +1,12 @@
|
||||
import { getProviderLabel } from '@renderer/i18n/label'
|
||||
import { Provider } from '@renderer/types'
|
||||
import { oauthWithAihubmix, oauthWithPPIO, oauthWithSiliconFlow, oauthWithTokenFlux } from '@renderer/utils/oauth'
|
||||
import {
|
||||
oauthWith302AI,
|
||||
oauthWithAihubmix,
|
||||
oauthWithPPIO,
|
||||
oauthWithSiliconFlow,
|
||||
oauthWithTokenFlux
|
||||
} from '@renderer/utils/oauth'
|
||||
import { Button, ButtonProps } from 'antd'
|
||||
import { FC } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
@ -36,6 +42,10 @@ const OAuthButton: FC<Props> = ({ provider, onSuccess, ...buttonProps }) => {
|
||||
if (provider.id === 'tokenflux') {
|
||||
oauthWithTokenFlux()
|
||||
}
|
||||
|
||||
if (provider.id === '302ai') {
|
||||
oauthWith302AI(handleSuccess)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@ -61,8 +61,8 @@ const providers: ProviderConfig[] = [
|
||||
},
|
||||
{
|
||||
key: '302ai',
|
||||
name: '302AI',
|
||||
description: '302AI 平台 MCP 服务',
|
||||
name: '302.AI',
|
||||
description: '302.AI 平台 MCP 服务',
|
||||
discoverUrl: 'https://302.ai',
|
||||
apiKeyUrl: 'https://dash.302.ai/apis/list',
|
||||
tokenFieldName: 'token302aiToken',
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import AI302ProviderLogo from '@renderer/assets/images/providers/302ai.webp'
|
||||
import AiHubMixProviderLogo from '@renderer/assets/images/providers/aihubmix.webp'
|
||||
import PPIOProviderLogo from '@renderer/assets/images/providers/ppio.png'
|
||||
import SiliconFlowProviderLogo from '@renderer/assets/images/providers/silicon.png'
|
||||
@ -20,6 +21,7 @@ interface Props {
|
||||
}
|
||||
|
||||
const PROVIDER_LOGO_MAP = {
|
||||
'302ai': AI302ProviderLogo,
|
||||
silicon: SiliconFlowProviderLogo,
|
||||
aihubmix: AiHubMixProviderLogo,
|
||||
ppio: PPIOProviderLogo,
|
||||
|
||||
@ -12,11 +12,11 @@ export function getProviderName(id: string) {
|
||||
}
|
||||
|
||||
export function isProviderSupportAuth(provider: Provider) {
|
||||
const supportProviders = ['silicon', 'aihubmix', 'ppio', 'tokenflux']
|
||||
const supportProviders = ['302ai', 'silicon', 'aihubmix', 'ppio', 'tokenflux']
|
||||
return supportProviders.includes(provider.id)
|
||||
}
|
||||
|
||||
export function isProviderSupportCharge(provider: Provider) {
|
||||
const supportProviders = ['silicon', 'aihubmix', 'ppio']
|
||||
const supportProviders = ['302ai', 'silicon', 'aihubmix', 'ppio']
|
||||
return supportProviders.includes(provider.id)
|
||||
}
|
||||
|
||||
@ -151,6 +151,26 @@ export const oauthWithTokenFlux = async () => {
|
||||
'width=720,height=720,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,alwaysOnTop=yes,alwaysRaised=yes'
|
||||
)
|
||||
}
|
||||
export const oauthWith302AI = async (setKey) => {
|
||||
const authUrl = 'https://dash.302.ai/sso/login?app=cherry-ai.com&name=Cherry%20Studio'
|
||||
|
||||
const popup = window.open(
|
||||
authUrl,
|
||||
'oauth',
|
||||
'width=720,height=720,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,alwaysOnTop=yes,alwaysRaised=yes'
|
||||
)
|
||||
|
||||
const messageHandler = (event) => {
|
||||
if (event.data && event.data.data.apikey !== undefined) {
|
||||
setKey(event.data.data.apikey)
|
||||
popup?.close()
|
||||
window.removeEventListener('message', messageHandler)
|
||||
}
|
||||
}
|
||||
|
||||
window.removeEventListener('message', messageHandler)
|
||||
window.addEventListener('message', messageHandler)
|
||||
}
|
||||
|
||||
export const providerCharge = async (provider: string) => {
|
||||
const chargeUrlMap = {
|
||||
@ -173,6 +193,11 @@ export const providerCharge = async (provider: string) => {
|
||||
url: 'https://ppio.com/user/register?invited_by=JYT9GD&utm_source=github_cherry-studio&redirect=/billing',
|
||||
width: 900,
|
||||
height: 700
|
||||
},
|
||||
'302ai': {
|
||||
url: 'https://dash.302.ai/charge',
|
||||
width: 900,
|
||||
height: 700
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,6 +231,11 @@ export const providerBills = async (provider: string) => {
|
||||
url: 'https://ppio.com/user/register?invited_by=JYT9GD&utm_source=github_cherry-studio&redirect=/billing/billing-details',
|
||||
width: 900,
|
||||
height: 700
|
||||
},
|
||||
'302ai': {
|
||||
url: 'https://dash.302.ai/charge',
|
||||
width: 900,
|
||||
height: 700
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user