- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Absinthe 中使用内置的 GraphiQL 界面。如下:
pipeline :browser do
plug RemoteIp, headers: ~w[x-forwarded-for], proxies: ~w[]
plug :accepts, ["html", "json"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
end
scope "/graphiql" do
pipe_through :browser # Use the default browser stack
forward "/", Absinthe.Plug.GraphiQL,
schema: ApiWeb.Schema,
default_headers: {__MODULE__, :graphiql_headers},
context: %{pubsub: ApiWeb.Endpoint}
end
def graphiql_headers(conn) do
%{
"X-CSRF-Token" => Plug.CSRFProtection.get_csrf_token(),
}
end
我需要最终用户插入 Authentication: Bearer <JWT>
在界面中,然后需要为 sub: header 解开它,其中包含我的用户 ID,我需要在解析器中使用它。
用户可以配置自定义 header ,这没问题。如果他随后执行 GraphSQL 查询,该接口(interface)将向/graphiql 端点发出 POST。正是在这个点上,我想调用一些插件来检查 JWT 并检索用户信息。
我以为我可以使用 default_headers 选项,但这似乎只在 GET 请求期间调用。
我似乎需要不同的管道来 GET 和 POST 到/graphiql 端点,我该如何实现呢?我一定做错了什么......
请注意,如果我对 GET 和 POST 使用相同的管道,则仅在访问浏览器中的端点时就会检查 JWT,这是我不希望的。
最佳答案
是的,实际上我做了以下事情:
pipeline :authenticate_on_post_only do
plug ApiWeb.Plugs.Authenticate, post_only: true
end
scope "/graphiql" do
pipe_through [:browser, :authenticate_on_post_only]
forward "/", Absinthe.Plug.GraphiQL,
schema: ApiWeb.GraphQL,
socket: ApiWeb.GraphQLSocket
end
结合:
defmodule ApiWeb.Plugs.Authenticate do
use Plug.Builder
alias ApiWeb.Helpers.JWT
plug Joken.Plug, verify: &JWT.verify/0, on_error: &JWT.error/2
plug ApiWeb.Plugs.Subject
plug Backend.Plug.Session
def call(%Plug.Conn{method: "POST"} = conn, opts) do
conn = super(conn, opts) # calls the above plugs
put_private(conn, :absinthe, %{context: conn}) # for absinthe (GraphQL), for resolvers to re-use
end
def call(conn, opts) do
if opts[:post_only] do
conn
else
super(conn, opts) # calls the above plugs
end
end
end
当然,您可以使用您自己的任何身份验证插件,而不是我列出的那些。
我在同一模块中还有一个 REST API,我使用它的方式如下:
scope "/v1", ApiWeb do
pipe_through :api
<my resources here>
done
API 管道定义为:
pipeline :api do
plug :put_resp_content_type, "application/json"
plug :accepts, ["json"]
plug ApiWeb.Plugs.Authenticate
end
它将对任何类型的 HTTP 请求进行身份验证。
关于elixir - 在 Elixir Phoenix Absinthe GraphIQL 客户端中实现身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48303254/
我试图通过调用 api 并在查询中设置参数来获取特定项目。我正在尝试使用 find 函数,但在解析 graphiql 中的查询时它给了我错误。 这是我用promise调用api函数。 var requ
我们如何使用浏览器内的 GraphQL IDE 上传文件 GraphiQL ,这甚至可能吗? (除了base64编码的字符串) 一旦我有了文件流/文件内容,我就可以创建一个多部分请求并存储在 DB 或
有没有一种方法(或捷径)来填充查询的所有字段? 让我们以https://graphql.org/swapi-graphql/为例。 我知道通过ctrl + space我可以调用自动建议。 但是,如果我
我最近将 graphiql 网络应用程序部署到我使用的嵌入式设备上,该页面用额外的重音“A”字符标记。可能是什么原因造成的? 详细信息: 这在 Linux Chromium 和 Windows Chr
如何在生产中禁用 graphiql 但仍然能够在开发中访问它? 使用 express-graphql 我们可以做类似的事情 app.use('/graphql', graphqlHTTP({ sc
这个问题已经有答案了: Why does a GraphQL query return null? (6 个回答) 已关闭 4 年前。 我将 GraphQL 与 Sequelize 结合使用,并且有一
这个问题已经有答案了: Why does a GraphQL query return null? (6 个回答) 已关闭 4 年前。 我实际上正在使用 Neo4j DB 并使用 neo4j_movi
我正在创建一个 gatsby 插件。在开发中我没有收到任何错误或警告,但我在 graphiql 中看不到我的查询(或在 http://localhost:8000/___graphql ) modul
使用GraphQLHub我可以运行此查询来查找 Hacker News 上排名前三的新闻条目: { hn { topStories(limit: 3) { title
我正在使用 Graphiql 组件来渲染控制台,并希望通过内省(introspection)查询获取架构。问题是,如果组件在第一个自省(introspection)查询解决之前重新呈现(例如打开一个模
我已经使用 graphql-java 实现创建了一个 graphql 端点,我还安装并运行 graphiql,但我不知道如何将 graphql 连接到我的 graphql 端点。有人可以告诉我如何做到
有一个我不拥有的 graphql 端点,但它提供了一个公共(public)端点。我希望使用 graphiql 来反射(reflection)它。我对 graphql 完全陌生,所以我什至不知道这种事情
我在 Absinthe 中使用内置的 GraphiQL 界面。如下: pipeline :browser do plug RemoteIp, headers: ~w[x-forwarded
当我从 GraphiQL 发布突变时,以下请求有效,但在我的应用程序的客户端不起作用。 我在控制台中收到“POST http://localhost:3001/graphql 400(错误请求)”错误
我在网站上使用 Gatsby 和 graphql 以及 headless WordPress。 我想使用 gatsby-image 插件为来自 WordPress 的图像获取 srcSet 和模糊效果
我想我已经彻底检查了这段代码,但找不到错误请帮忙!!查询 id 时返回 null 此外,vscode 告诉我我的父级在解析函数中没有使用。我在这里做错了什么?? express --- const e
不确定我设置错了什么,但是当我使用 uvicorn mysite.asgi:application 在 uvicorn 中运行时,我没有得到 graphiql 界面: [32mINFO[0m:
我正在学习 GraphQL 并且是该技术的新手。我无法找出此语法错误的原因。当我在 graphiql 上对其进行测试时,它会引发意外的 token 语法错误 这是我的 server.js: const
我已经安装了 Apollo/GraphQL。当我通过 http://localhost:8080/graphql 访问 GraphiQL 时,我看到的是以下消息,而不是 GraphiQL 用户界面:
我正在尝试制作 GraphQL Java server使用 GraphiQL 服务器。 使用本地运行的 GraphiQL,我提交了一个包含以下参数的查询: 我的 Spring Controller (
我是一名优秀的程序员,十分优秀!