Open xyk98 opened 1 month ago
To resolve the HTTP 401 Unauthorized error when running the CypherAPI on the Swagger page after deploying HugeGraph and HugeGraph-Hubble via Docker, you need to ensure that the correct authorization headers are being sent with your requests. The CypherAPI
class expects either a Basic or Bearer token for authorization.
Basic Authentication:
Authorization
header with the value Basic <encoded-credentials>
.Bearer Token Authentication:
Authorization
header with the value Bearer <token>
.If your username is user
and your password is password
, you need to encode user:password
in Base64. The encoded string for user:password
is dXNlcjpwYXNzd29yZA==
.
Add the following header to your request:
Authorization: Basic dXNlcjpwYXNzd29yZA==
If you have a token your_token
, add the following header to your request:
Authorization: Bearer your_token
If you are using Swagger UI, you can add the authorization header as follows:
// Add this script to your Swagger UI initialization code
swaggerUi.api.clientAuthorizations.add(
'basicAuth',
new SwaggerClient.ApiKeyAuthorization('Authorization', 'Basic dXNlcjpwYXNzd29yZA==', 'header')
);
// For Bearer token
swaggerUi.api.clientAuthorizations.add(
'bearerAuth',
new SwaggerClient.ApiKeyAuthorization('Authorization', 'Bearer your_token', 'header')
);
Ensure that you replace dXNlcjpwYXNzd29yZA==
and your_token
with your actual encoded credentials and token, respectively.
Additionally, verify that the authentication settings in your gremlin-server.yaml
and rest-server.properties
files are correctly configured. The gremlin-server.yaml
file should have the following authentication settings:
authentication: {
authenticator: org.apache.hugegraph.auth.StandardAuthenticator,
authenticationHandler: org.apache.hugegraph.auth.WsAndHttpBasicAuthHandler,
config: {tokens: conf/rest-server.properties}
}
Ensure that the rest-server.properties
file contains the correct token configurations as referenced in the gremlin-server.yaml
file. This setup ensures that the server is properly configured to handle authentication requests.
The HugeGraphAuthProxy
class in HugeGraph handles various authentication and authorization tasks, ensuring that the correct permissions are verified for different operations [1][2][3].
To continue the conversation, mention @dosu.
Due to the lack of activity, the current issue is marked as stale and will be closed after 20 days, any update will remove the stale label
Problem Type (问题类型)
server status (启动/运行异常)
Before submit
Environment (环境信息)
Your Question (问题描述)
After deploying hugegraph and hugegraph-hubble via docker, running the example using CypherAPI on the swagger page reported an error.
CypherAPI [GET] Input: graph:hugegraph cypher:match(n:person) return n.name as name order by n.name limit 1
Error message:
Curl: curl -X 'GET' \ 'http://172.18.30.240:18080/graphs/hugegraph/cypher?cypher=match%28n%3Aperson%29%20return%20n.name%20as%20name%20order%20by%20n.name%20limit%201' \ -H 'accept: application/json;charset=UTF-8'
Request URL: http://172.18.30.240:18080/graphs/hugegraph/cypher?cypher=match%28n%3Aperson%29%20return%20n.name%20as%20name%20order%20by%20n.name%20limit%201
Response body: { "exception": "class jakarta.ws.rs.NotAuthorizedException", "message": "HTTP 401 Unauthorized", "cause": "" }
docker-compose.yml: version: '3' services: hugegraph-server: image: hugegraph/hugegraph:1.2.0 container_name: hugegraph restart: always environment:
18080:8080
hugegraph-hubble: image: hugegraph/hubble:1.2.0 container_name: hugegraph-hubble restart: always environment:
Vertex/Edge example (问题点 / 边数据举例)
No response
Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)
No response