简体   繁体   English

将 jwt 转换为在 android 应用程序上使用 Cookie(sessionid+csrf Token)

[英]converting jwt to using Cookie(sessionid+csrf Token) on android app

My application requires that only one account can use it.我的应用程序要求只有一个帐户可以使用它。 So, My team decided to use session and Cookie because they can control the access.所以,我的团队决定使用 session 和Cookie ,因为他们可以控制访问。 So, the Cookie has sessionid and csrf Token.因此,Cookie 具有 sessionid 和 csrf Token。

As far as I know, Cookie is for Browser.据我所知,Cookie是给浏览器的。 I don't know if it's a good strategy for Native Application.我不知道这是否是 Native Application 的好策略。 And I don't know if csrf Token is needed for Native app.而且我不知道原生应用是否需要csrf Token。 And also, Cookie seems less safe than JWT.而且,Cookie 似乎不如 JWT 安全。

I get Cookie content from Headers(Set-Cookie) and also send it in Cookie Header & X-CSRFToken Header.我从 Headers(Set-Cookie) 获取 Cookie 内容,并将其发送到 Cookie Header & X-CSRFToken Header。

Can you describe the pros and cons, and your opinion about this migration?你能描述一下优缺点,以及你对这种迁移的看法吗?

From a mobile app perspective using cookies with a session ID doesn't differ much from using opaque access tokens.从移动应用程序的角度来看,使用 cookies 和 session ID 与使用不透明访问令牌没有太大区别。 For the mobile app, it's just a string that you need to get from one place (response body/header, etc.), and put it in another ( Authorization header or Cookie header).对于移动应用程序,它只是一个字符串,您需要从一个地方(响应正文/标头等)获取,并将其放在另一个地方( Authorization header 或Cookie标头)。 All the security features of cookies are implemented by the browser so you will not use them anyway. cookies 的所有安全功能都是由浏览器实现的,因此您无论如何都不会使用它们。

As for the CSRF token, you have to remember that the API does not have a way of knowing whether it's the mobile app making the request or the browser.至于 CSRF 令牌,您必须记住 API 无法知道发出请求的是移动应用程序还是浏览器。 As you will be using cookies it's recommended to also have proper CSRF protection in place.由于您将使用 cookies,因此建议您也进行适当的 CSRF 保护。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM