Skip to content

Commit 0c009d7

Browse files
niiish32x越鸿csunnyanotherso1adusx1981
authored
feat: add alibaba oauth comfig (#167)
Co-authored-by: 越鸿 <nishenghao.nsh@oceanbase.com> Co-authored-by: magic.chen <cfqsunny@163.com> Co-authored-by: AnotherSola <38176179+anotherso1a@users.noreply.github.com> Co-authored-by: 坐山客 <157097695@qq.com> Co-authored-by: Aries-ckt <916701291@qq.com> Co-authored-by: heyzcat <31226585+heyzcat@users.noreply.github.com> Co-authored-by: yangchuan <yangchuan@oppo.com> Co-authored-by: neuqliu <1196932066@qq.com> Co-authored-by: yanzhiyong <932374019@qq.com> Co-authored-by: gallopxiong <62653374+josehap@users.noreply.github.com> Co-authored-by: gallopxiong <gallopxiong@tencent.com> Co-authored-by: XinyueDu <51403464+XinyueDu@users.noreply.github.com> Co-authored-by: duxinyue.dxy <duxinyue.dxy@antgroup.com> Co-authored-by: Ikko Eltociear Ashimine <eltociear@gmail.com> Co-authored-by: lpq131004 <66124950+lpq131004@users.noreply.github.com> Co-authored-by: chenketing.ckt <chenketing.ckt@antgroup.com> Co-authored-by: Aries-ckt <ariesketing@gmail.com> Co-authored-by: Lin-Zhipeng <2542207527@qq.com> Co-authored-by: zhipeng.lin <zhipeng.lin@shopee.com> Co-authored-by: Claude (GLM-4.7) <noreply@anthropic.com> Co-authored-by: tptpp <544016459@qq.com> Co-authored-by: RichardoMu <44485717+RichardoMrMu@users.noreply.github.com> Co-authored-by: RichardoMrMu <tianbowen.tbw@antgroup.com> Co-authored-by: yhjun1026 <yhjun1026@users.noreply.github.com>
1 parent 8d1b84c commit 0c009d7

224 files changed

Lines changed: 1357 additions & 2010 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

assets/schema/derisk.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use derisk;
99
-- MySQL DDL Script for Derisk
1010
-- Version: 0.3.0
1111
-- Generated from SQLAlchemy ORM Models
12-
-- Generated: 2026-03-16 15:22:00
12+
-- Generated: 2026-03-18 00:22:14
1313
-- ============================================================
1414

1515
SET NAMES utf8mb4;

configs/derisk-ob.toml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
[system]
2+
# Load language from environment variable(It is set by the hook)
3+
language = "${env:DERISK_LANG:-zh}"
4+
log_level = "INFO"
5+
api_keys = []
6+
encrypt_key = "${ENCRYPT_KEY:-your_secret_key}"
7+
8+
# Server Configurations
9+
[service.web]
10+
host = "0.0.0.0"
11+
port = 7777
12+
model_storage = "database"
13+
web_url = "https://localhost:${env:WEB_SERVER_PORT:-7777}"
14+
15+
[service.web.database]
16+
type = "sqlite"
17+
path = "pilot/meta_data/derisk.db"
18+
19+
[service.web.trace]
20+
file = "${env:TRACE_FILE_DIR:-logs}/derisk_webserver_tracer.jsonl"
21+
22+
[service.model.worker]
23+
host = "127.0.0.1"
24+
25+
[agent.llm]
26+
# (可选) 全局配置
27+
temperature = 0.5
28+
29+
[[agent.llm.provider]]
30+
provider = "openai"
31+
api_base = "https://dashscope.aliyuncs.com/compatible-mode/v1"
32+
api_key = "${DASHSCOPE_API_KEY:-sk-...}"
33+
34+
[[agent.llm.provider.model]]
35+
name = "deepseek-r1"
36+
temperature = 0.7
37+
max_new_tokens = 4096
38+
[[agent.llm.provider.model]]
39+
name = "deepseek-v3"
40+
temperature = 0.7
41+
max_new_tokens = 4096
42+
[[agent.llm.provider.model]]
43+
name = "Kimi-k2"
44+
temperature = 0.7
45+
max_new_tokens = 4096
46+
[[agent.llm.provider.model]]
47+
name = "qwen-plus"
48+
temperature = 0.7
49+
max_new_tokens = 4096
50+
[[agent.llm.provider.model]]
51+
name = "qwen-vl-max"
52+
temperature = 0.7
53+
max_new_tokens = 4096
54+
55+
[[agent.llm.provider.model]]
56+
name = "glm-5"
57+
temperature = 0.7
58+
max_new_tokens = 4096
59+
60+
[[serves]]
61+
type = "file"
62+
# Default backend for file server
63+
default_backend = "oss"
64+
65+
#[[serves.backends]]
66+
#type = "oss"
67+
#endpoint = "https://oss-cn-beijing.aliyuncs.com"
68+
#region = "oss-cn-beijing"
69+
#access_key_id = "${env:OSS_ACCESS_KEY_ID:-xxx}"
70+
#access_key_secret = "${env:OSS_ACCESS_KEY_SECRET:-xxx}"
71+
#fixed_bucket = "openderisk"
72+
#
73+
#
74+
#[sandbox]
75+
#type="local"
76+
#template_id=""
77+
#user_id="derisk"
78+
#agent_name="derisk"
79+
#repo_url=""
80+
#work_dir="/home/ubuntu"
81+
#skill_dir="/mnt/derisk/skills"
82+
#oss_ak="${env:OSS_ACCESS_KEY_ID:-xxx}"
83+
#oss_sk="${env:OSS_ACCESS_KEY_SECRET:-xxx}"
84+
#oss_endpoint="https://oss-cn-beijing.aliyuncs.com"
85+
#oss_bucket_name="openderisk"

packages/derisk-app/src/derisk_app/auth/oauth.py

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
GITHUB_TOKEN_URL = "https://github.com/login/oauth/access_token"
1313
GITHUB_USERINFO_URL = "https://api.github.com/user"
1414

15+
# Alibaba-inc (MOZI) OAuth2 endpoints
16+
MOZI_AUTH_URL = "https://mozi-login.alibaba-inc.com/oauth2/auth.htm"
17+
MOZI_TOKEN_URL = "https://mozi-login.alibaba-inc.com/rpc/oauth2/access_token.json"
18+
MOZI_USERINFO_URL = "https://mozi-login.alibaba-inc.com/rpc/oauth2/user_info.json"
19+
1520

1621
class OAuth2Service:
1722
"""OAuth2 flow service - handles login redirect, callback, userinfo fetch."""
@@ -40,6 +45,21 @@ def get_authorization_url(
4045
}
4146
qs = "&".join(f"{k}={v}" for k, v in params.items())
4247
return f"{GITHUB_AUTH_URL}?{qs}"
48+
elif provider_config.get("type") == "alibaba-inc":
49+
client_id = provider_config.get("client_id", "")
50+
scope = provider_config.get("scope", "get_user_info")
51+
if not client_id:
52+
return None
53+
params = {
54+
"client_id": client_id,
55+
"redirect_uri": redirect_uri,
56+
"state": state,
57+
"response_type": "code",
58+
}
59+
if scope:
60+
params["scope"] = scope
61+
qs = "&".join(f"{k}={v}" for k, v in params.items())
62+
return f"{MOZI_AUTH_URL}?{qs}"
4363
elif provider_config.get("type") == "custom":
4464
auth_url = provider_config.get("authorization_url", "")
4565
client_id = provider_config.get("client_id", "")
@@ -76,6 +96,16 @@ async def exchange_code_for_token(
7696
"redirect_uri": redirect_uri,
7797
}
7898
headers = {"Accept": "application/json"}
99+
elif provider_config.get("type") == "alibaba-inc":
100+
token_url = MOZI_TOKEN_URL
101+
data = {
102+
"client_id": provider_config.get("client_id", ""),
103+
"client_secret": provider_config.get("client_secret", ""),
104+
"code": code,
105+
"redirect_uri": redirect_uri,
106+
"grant_type": "authorization_code",
107+
}
108+
headers = {"Accept": "application/json"}
79109
elif provider_config.get("type") == "custom":
80110
token_url = provider_config.get("token_url", "")
81111
if not token_url:
@@ -108,6 +138,10 @@ async def fetch_userinfo(
108138
if provider_config.get("type") == "github":
109139
userinfo_url = GITHUB_USERINFO_URL
110140
headers = {"Authorization": f"Bearer {access_token}"}
141+
elif provider_config.get("type") == "alibaba-inc":
142+
userinfo_url = MOZI_USERINFO_URL
143+
# MOZI format: POST with access_token in body
144+
headers = {"Content-Type": "application/x-www-form-urlencoded"}
111145
elif provider_config.get("type") == "custom":
112146
userinfo_url = provider_config.get("userinfo_url", "")
113147
if not userinfo_url:
@@ -118,18 +152,22 @@ async def fetch_userinfo(
118152

119153
try:
120154
async with httpx.AsyncClient() as client:
121-
resp = await client.get(userinfo_url, headers=headers)
155+
if provider_config.get("type") == "alibaba-inc":
156+
resp = await client.post(
157+
userinfo_url, data={"access_token": access_token}, headers=headers
158+
)
159+
else:
160+
resp = await client.get(userinfo_url, headers=headers)
122161
resp.raise_for_status()
123162
data = resp.json()
124-
# Normalize to common format
125163
return {
126-
"id": str(data.get("id", "")),
127-
"login": data.get("login", ""),
128-
"username": data.get("username", data.get("login", "")),
129-
"name": data.get("name", ""),
164+
"id": str(data.get("openId") or data.get("id") or ""),
165+
"login": data.get("login", data.get("account", "")),
166+
"username": data.get("username", data.get("nickNameCn", "")),
167+
"name": data.get("name", data.get("realName", data.get("lastName", ""))),
130168
"email": data.get("email", ""),
131-
"avatar_url": data.get("avatar_url", ""),
132-
"avatar": data.get("avatar", data.get("avatar_url", "")),
169+
"avatar_url": data.get("avatar_url", data.get("avatar", "")),
170+
"avatar": data.get("avatar", ""),
133171
"picture": data.get("picture", ""),
134172
}
135173
except Exception as e:

packages/derisk-app/src/derisk_app/static/web/404.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

packages/derisk-app/src/derisk_app/static/web/404/index.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

packages/derisk-app/src/derisk_app/static/web/_next/static/chunks/1081-4a99378a7bd38d7c.js renamed to packages/derisk-app/src/derisk_app/static/web/_next/static/chunks/1081-6591d8b32eeed670.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)