← 返回
未分类 Key 中文

Ainative Auth Guide

Implement authentication for AINative APIs. Use when (1) Choosing between API key and JWT auth, (2) Registering/logging in users, (3) Refreshing tokens, (4)...
为AINative API实现身份验证。适用于:(1) 在API密钥和JWT认证之间选择;(2) 用户注册/登录;(3) 刷新令牌;(4)...
urbantech urbantech 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 需要
★ 0
Stars
📥 391
下载
💾 1
安装
1
版本
#latest

概述

AINative Authentication Guide

Auth Methods

MethodUse CaseHeader
--------------------------
API KeyServer-side, agents, SDKs, MCP toolsX-API-Key: ak_...
Bearer JWTUser sessions, web appsAuthorization: Bearer
OAuth2Social login (LinkedIn, GitHub)Standard OAuth2 flow

API Key Auth (Simplest)

Get a key via npx zerodb init or from the dashboard.

import requests

response = requests.get(
    "https://api.ainative.studio/api/v1/public/credits/balance",
    headers={"X-API-Key": "ak_your_key"}
)
const res = await fetch("https://api.ainative.studio/api/v1/public/credits/balance", {
  headers: { "X-API-Key": "ak_your_key" }
});

Email/Password Registration & Login

# Register
resp = requests.post(
    "https://api.ainative.studio/api/v1/auth/register",
    json={"email": "user@example.com", "password": "securepass", "name": "Alice"}
)
token = resp.json()["access_token"]

# Login
resp = requests.post(
    "https://api.ainative.studio/api/v1/auth/login",
    json={"email": "user@example.com", "password": "securepass"}
)
access_token = resp.json()["access_token"]
refresh_token = resp.json()["refresh_token"]

JWT Usage

headers = {"Authorization": f"Bearer {access_token}"}
me = requests.get("https://api.ainative.studio/api/v1/users/me", headers=headers).json()

Token Refresh

resp = requests.post(
    "https://api.ainative.studio/api/v1/auth/refresh",
    json={"refresh_token": refresh_token}
)
new_access_token = resp.json()["access_token"]

Logout

requests.post(
    "https://api.ainative.studio/api/v1/auth/logout",
    headers={"Authorization": f"Bearer {access_token}"}
)

OAuth2 Social Login

# LinkedIn
resp = requests.post(
    "https://api.ainative.studio/api/v1/auth/linkedin/callback",
    json={"code": oauth_code, "redirect_uri": "https://yourapp.com/callback"}
)

# GitHub
resp = requests.post(
    "https://api.ainative.studio/api/v1/auth/github/callback",
    json={"code": oauth_code, "redirect_uri": "https://yourapp.com/callback"}
)
token = resp.json()["access_token"]

Next.js Middleware

// middleware.ts
import { createMiddleware } from '@ainative/next-sdk/middleware';

export const middleware = createMiddleware({
  apiKey: process.env.AINATIVE_API_KEY!,
  protectedPaths: ['/dashboard', '/api/protected'],
  loginPath: '/login',
});

Password Reset

# Request reset email
requests.post("https://api.ainative.studio/api/v1/auth/forgot-password",
    json={"email": "user@example.com"})

# Set new password with token from email
requests.post("https://api.ainative.studio/api/v1/auth/reset-password",
    json={"token": "reset_token_from_email", "new_password": "newpassword"})

Auth Endpoints

EndpointMethodDescription
-------------------------------
/api/v1/auth/registerPOSTCreate account
/api/v1/auth/loginPOSTEmail/password → JWT
/api/v1/auth/logoutPOSTInvalidate session
/api/v1/auth/refreshPOSTRefresh access token
/api/v1/users/meGETCurrent user profile
/api/v1/auth/verify-emailPOSTVerify email address
/api/v1/auth/forgot-passwordPOSTSend reset email
/api/v1/auth/reset-passwordPOSTApply new password
/api/v1/auth/linkedin/callbackPOSTLinkedIn OAuth2
/api/v1/auth/github/callbackPOSTGitHub OAuth2

Error Codes

StatusMeaning
-----------------
401Invalid or missing token/key
403Valid auth, insufficient permissions
409Email already registered

References

  • src/backend/app/api/v1/endpoints/auth.py — Auth endpoint implementation
  • packages/sdks/nextjs/src/middleware/ — Next.js auth middleware
  • docs/guides/AUTHENTICATION.md — Full authentication guide

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-31 09:09 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

dev-programming

Mcporter

steipete
使用 mcporter CLI 直接列出、配置、认证及调用 MCP 服务器/工具(支持 HTTP 或 stdio),涵盖临时服务器、配置编辑及 CLI/类型生成功能。
★ 196 📥 67,957
dev-programming

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 76 📥 182,443
it-ops-security

Ci Cd Compliance

urbantech
CI/CD 流水线需求和部署标准。适用于:(1) 设置 CI/CD 流水线,(2) 调试 CI 失败问题,(3) 配置部署工作流
★ 0 📥 604