简体   繁体   English

Python GraphQL gql 客户端认证

[英]Python GraphQL gql client authentication

I´m having hard time to use GraphQL with Python since the suggested library: gql is completely undocumented.我很难在 Python 中使用 GraphQL,因为建议的库: gql完全没有记录。

How ever I found out that to provide the api url I need to pass a RequestsHTTPTransport object to Client like this:我怎么发现要提供 api url,我需要像这样将 RequestsHTTPTransport 对象传递给客户端:

client = Client(transport=RequestsHTTPTransport(url='https://some.api.com/v3/graphql'))

but how to provide credentials like the Bearer Key?但是如何提供像 Bearer Key 这样的凭证呢?

PS I noticed that it RequestsHTTPTransport accepts also a auth param which is described as: PS 我注意到它 RequestsHTTPTransport 也接受一个 auth 参数,它被描述为:

:param auth: Auth tuple or callable to enable Basic/Digest/Custom HTTP Auth

how ever I still can not find out how to create this tuple or callable to work with a Bearer Key :(我如何仍然无法找到如何创建此元组或可调用以使用不记名密钥:(

Thanks in advise谢谢指教

You can add it in the headers.您可以将其添加到标题中。

reqHeaders = {
    'x-api-key' : API_KEY,
    'Authorization': 'Bearer ' + TOKEN_KEY // This is the key
}

_transport = RequestsHTTPTransport(
    url=API_ENDPOINT,
    headers = reqHeaders,
    use_json=True,
)

client = Client(
    transport = _transport,
    fetch_schema_from_transport=True,
)

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

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