gpt4 book ai didi

f# - 保护 WebSharper 远程调用

转载 作者:行者123 更新时间:2023-12-01 09:59:04 26 4
gpt4 key购买 nike

引用自 WebSharper 2.5 alpah 文档,远程处理组件假定:

RPC-callable methods are safe to call from the web by an unauthenticated client.

有没有办法保护远程调用,以便它们只能从经过身份验证的客户端调用?

最佳答案

WebSharper 网站中的示例之一是一个聊天应用程序,它似乎通过提供返回身份验证 token 的登录方法来做到这一点,然后需要调用其他功能:

[<Rpc>]
let Login (user: string) : Option<Auth.Token> =
let s = State.Get()
if s.Users.ContainsKey user then
None
else
// (snip)
user |> Auth.Generate |> Some

[<Rpc>]
let Poll (auth: Auth.Token) (time: int) =
// (snip)

完整的聊天示例可以在这里找到:http://www.websharper.com/samples/Chat

关于f# - 保护 WebSharper 远程调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19347870/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com