dbeaver/cloudbeaver

How execute gql queries after successful login?

romalukin opened this issue · 2 comments

Hi there!

I'm looking to set up user management automation using GraphQL, but I’m a bit stuck. I found this issue and tried the authentication query it mentioned. The console return "authStatus": "SUCCESS", and I don't know what to do next (in my case listUsers query).

I was expecting the console to return a token that I could use in the authorization header for future queries, but I didn’t see one.

Since I’m new to GraphQL, could you help me figure out how to proceed with queries after a successful login? Any guidance would be much appreciated!

Thanks!

Hi, we use cookies to work with GraphQL queries. Here is an example of an authorization request:

 curl -v -X POST https://localhost:8080/api/gql \
--header "Content-Type: application/json" \
--data '{ "query": "query authLogin($provider: ID!, $configuration: ID, $credentials: Object, $linkUser: Boolean, $forceSessionsLogout: Boolean) {
  authInfo: authLogin(
    provider: $provider
    configuration: $configuration
    credentials: $credentials
    linkUser: $linkUser
    forceSessionsLogout: $forceSessionsLogout
  ) {
    redirectLink
    authId
    authStatus
    userTokens {
      message
    }
  }
}",
  "variables": {
  "provider": "local",
  "credentials": {
    "user": "cbadmin",
    "password": "encrypted_password"
  },
  "linkUser": false,
  "forceSessionsLogout": true
}
}'

You need to pay attention to the Set-Cookie header in the response:

image
The response will return the session id and the session expiration time if there are no other requests.

Accordingly, the following request will look like this (taking into account the passed cookie):

curl -v -X POST  https://localhost:8080/api/gql \
--header "Content-Type: application/json" \
--cookie "cb-session-id=16w5j***********xxb76" \
--data '{"query": "query getUsersList($page: PageInput!, $filter: AdminUserFilterInput!) {
  users: listUsers(page: $page, filter: $filter) {
    userId
    grantedTeams
    linkedAuthProviders
    origins {
      type
      subType
      displayName
    }
    enabled
  }
}",
  "variables": {
  "page": {
    "offset": 0,
    "limit": 100
    },
  "filter": {
    "userIdMask": "",
    "enabledState": true
    },
  "customIncludeBase": true
  }
}'

You can also activate the GraphQL console using the following documentation: https://dbeaver.com/docs/cloudbeaver/Server-API-explorer/

Thanks a lot!