中继认证GraphQL [英] Authentication in Relay & GraphQL

查看:26
本文介绍了中继认证GraphQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 react 和 relay 开发一个应用程序,现在我一直在实施身份验证.

I've been working on an application using react and relay, and now I'm stuck on implementing authentication.

我知道您可以通过 GraphQL 解析函数中可用的上下文将值传递给每个 graphql 请求.

I know that you can pass value to each graphql request through the context which is available in GraphQL resolves functions.

我对传递什么以及如何传递更加困惑.

I'm more confused about what to pass for it and how.

使用 JSON Web 令牌、护照或其他东西会更好吗?我应该如何为用户传递标识符?

Is it better to use JSON Web token, passport, something else? And how should I pass the identifier for the user?

基本上我在问什么,什么最适合 Relay:jwt、护照、其他?以及如何将其与继电器连接起来.谢谢!

Basically what I'm asking, What is best suitable for Relay: jwt, passport, something else? And how to hook it up with relay. Thanks!

推荐答案

我认为最好的办法是学习一些入门工具包.不幸的是,这些工具包几乎都没有提供完整的 JWT 实现——其中许多似乎只完成了一半.

I think your best bet is to study some of the starter kit. Unfortunately almost none of these kits provide a complete JWT implementation - many of them seem to only have a half done one.

退房:

  • 中继认证.您的里程可能会有所不同 - 它涵盖了整个概念,但有一些错误.
  • 通用继电器样板.那是相当惊人和完整的,但它是一头野兽,工作起来可能有点不知所措,因为它还包括 iOS/Android 应用程序创建.
  • 中继入门套件.在撰写本文时,它只有 FB auth 设置(因此没有正常的登录表单),它确实设置了一个 JWT cookie.我相信将他们所有的登录路由迁移到 GraphQL 已经在路线图上,因为现在它有点混合.
  • Relay Authentication. Your mileage may vary - it covers the whole concept but has some bugs.
  • Universal Relay Boilerplate. That one is pretty amazing and complete but is a beast and can be a bit overwhelming to work from since it also includes iOS/Android app creation.
  • Relay Starter Kit. At the time of writing it only has FB auth setup (so no regular login form that works) through it does set a JWT cookie. I believe that migrating all their login routes to GraphQL is on the roadmap as right now it's a bit of a hybrid.

就您的 jwt/护照问题而言.它们不是相互排斥的.Passport 可以处理 jwt 身份验证,尽管我个人不使用它并直接使用 jwt 库.这并不难 - 你可以在 server Relay Starter Kit 文件.

As far as your jwt/passport question. They are not mutually exclusive. Passport can handle jwt auth though personally I dont use it and work directly with a jwt library. It's not very hard to do - you can see it in the server file of the Relay Starter Kit.

JWT 令牌通常在标头周围传递,但是已经转向将这些令牌存储在 HttpOnly cookie 中(请参阅此 文章).该方法的好处是您不需要处理通过 Relay 传递令牌.

JWT tokens are usually passed around the headers however there has been a shift towards storing these tokens in HttpOnly cookies (see this article). The upside of that method is that you don't need to deal with passing the token around with Relay.

这篇关于中继认证GraphQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆