gpt4 book ai didi

android - 相当于在没有浏览器的Mobile app上存储cookie

转载 作者:搜寻专家 更新时间:2023-11-01 08:17:35 25 4
gpt4 key购买 nike

我想知道在移动应用程序上存储 key 以进行 session 身份验证的机制。我有一个 Tornado 网络服务器,它将使用第三方外部服务来对用户进行身份验证,例如 Facebook 或谷歌。我熟悉在使用浏览器时使用 set_secure_cookie 存储 cookie。但是,如果移动应用程序现在正在连接并进行身份验证怎么办。我将使用什么机制来存储一个 secret ,例如用于 future session 身份验证的安全 cookie?下面显示了验证用户的代码:

class GoogleOAuth2LoginHandler(tornado.web.RequestHandler,
tornado.auth.GoogleOAuth2Mixin):
async def get(self):
if self.get_argument('code', False):
user = await self.get_authenticated_user(
redirect_uri='http://your.site.com/auth/google',
code=self.get_argument('code'))
# Save the user with e.g. set_secure_cookie
else:
await self.authorize_redirect(
redirect_uri='http://your.site.com/auth/google',
client_id=self.settings['google_oauth']['key'],
scope=['profile', 'email'],
response_type='code',
extra_params={'approval_prompt': 'auto'})

对于不依赖浏览器和 cookie 支持的移动应用程序,如何修改它?

最佳答案

在 iOS 中,NSHTTPCookie 类中有一个 API,您可以在其中保存整个 http 响应字符串。代码将类似于下面创建 cookie 的内容。

if let requestUrl = url {
let httpCookies = HTTPCookie.cookies(withResponseHeaderFields: response.allHeaderFields as! [String : String], for: requestUrl)
}

然后你就可以保存cookie了,

HTTPCookieStorage.shared.setCookies(httpCookie, for: url, mainDocumentURL: url)

如果需要,您还可以访问此 cookie 并将其设置到 WebView。

关于android - 相当于在没有浏览器的Mobile app上存储cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57968568/

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