Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

开场白的apikey 生成方式是什么,会不会过期? #7729

Closed
4 tasks done
haike-1213 opened this issue Aug 28, 2024 · 5 comments
Closed
4 tasks done

开场白的apikey 生成方式是什么,会不会过期? #7729

haike-1213 opened this issue Aug 28, 2024 · 5 comments
Labels
📚 documentation Improvements or additions to documentation

Comments

@haike-1213
Copy link
Contributor

Self Checks

  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Provide a description of requested docs changes

开场白的apikey 生成方式是什么,会不会过期?

Copy link

dosubot bot commented Aug 28, 2024

开场白的 API key 生成方式是使用 generate_token 函数。生成的 API key 会在 3 分钟(180 秒)后过期,这是由 API_TOKEN_TTL_SECONDS 常量定义的。

以下是相关代码:

API_TOKEN_TTL_SECONDS = 3 * 60

@cachetools.func.ttl_cache(maxsize=10, ttl=API_TOKEN_TTL_SECONDS - 30)
def generate_token(apikey: str):
    try:
        api_key, secret = apikey.split(".")
    except Exception as e:
        raise Exception("invalid api_key", e)

    payload = {
        "api_key": api_key,
        "exp": int(round(time.time() * 1000)) + API_TOKEN_TTL_SECONDS * 1000,
        "timestamp": int(round(time.time() * 1000)),
    }
    ret = jwt.encode(
        payload,
        secret,
        algorithm="HS256",
        headers={"alg": "HS256", "sign_type": "SIGN"},
    )
    return ret

生成的 token 会在 3 分钟后过期[1].

To continue talking to Dosu, mention @dosu.

@dosubot dosubot bot added the 📚 documentation Improvements or additions to documentation label Aug 28, 2024
@haike-1213
Copy link
Contributor Author

/api/parameters 里面的 authorization 会过期吗?

Copy link

dosubot bot commented Aug 28, 2024

/api/parameters 端点中的 authorization 参数会过期。Dify 平台使用 JWT(JSON Web Tokens)进行身份验证,JWT 的过期时间由配置文件中的 "{token_type.upper()}_TOKEN_EXPIRY_HOURS" 键来设置。具体的过期时间取决于配置中的设置值[1].

此外,Dify 还支持通过 GitHub 和 Google 等提供商进行 OAuth 身份验证,这些提供商的访问令牌也有各自的过期时间[2].

To continue talking to Dosu, mention @dosu.

@crazywoola
Copy link
Member

I confirm that I am using English to submit report (我已阅读并同意 #1542).

@crazywoola
Copy link
Member

你好,提问之前请查看我们相关的语言政策,为了更好的交流请使用英语并且使用相应的模版进行提交,有疑问可以使用 Discussion,我注意到你这边已经多次违反我们的语言政策,如果后续还是不遵守我们相关政策,我们会进行相关封禁处理。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants