Jump to content

Authorication fails with GraphQL API


Recommended Posts

We are currently testing the new GraphQL API, but the authorization of the requests is always failing.

We have changed the settings of our OAuth client to "Rest & GraphQL" in AdminCP, but it is not clear from the documentation how to send the access token. The usual method via authorization header (tested with and without Bearer Prefix) returns error "INVALID_ACCESS_TOKEN" and the header 'X-Authorization' with Access Token returns an "INVALID_API_KEY" error.

Can anyone provide an example of a successful request to the GraphQL API?

 

This is an example of a PHP script we used to access the GraphQL API (keys have been replaced for screenshot)

Could contain: Page, Text

@Matthias Martin FYI

Edited by Christian Meixner
Link to comment
Share on other sites

Well, I've actually linked to exactly that documentation in my post above and for me it does not help to explain how exactly authenticating against GraphQL works.

The given example for "Using GraphQL outside of the Invision Framework" seem to use framework/invision internals or hides significant information in the referenced but not shown "init.php" file.

What we are trying to do, is to ran a either PHP or nodeJS based application outside invision and have that application to access the invision forum using the GraphQL api. Is that even possible?

Right now we are using the REST API, which works quite well but is a bit limited in some ways that we hope to get around with the GraphQL API.

Link to comment
Share on other sites

But the example does not show how to use the key/API from outside the Invision platform because you can not use this code in an application outside Invision, because it is part of the Invision platform/framework.

$result = \IPS\Http\Url::external( rtrim( \IPS\Settings::i()->base_url, \'/\' ) . \'/api/graphql/index.php\' )->request()->login( $key, "" )

So this example does not help here. You can not call \IPS\Http\Url::external() outside of invision.

I'm looking for an example for "Using GraphQL outside of the Invision Framework" as stated in the headline of the documentation.

Or what am I getting wrong here?

Link to comment
Share on other sites

Can anyone assist here please? I'd love to get answers on the following two questions at least:

1. Is the GraphQL API supposed to be used (accessed) from outside the invision platform itself (meaning any 3rd party app can query that API)?

2. If so, can someone provide an example request against the GraphQL API that does not utilize Invision Power Service (IPS) internal methods as in the example of the documentation?

Link to comment
Share on other sites

Hi Christian, 

`login()` is analogous to HTTP Basic Auth.

	public function login( string $username, string $password ): static
	{
		curl_setopt_array( $this->curl, array(
			CURLOPT_HTTPAUTH		=> CURLAUTH_BASIC,
			CURLOPT_USERPWD			=> "{$username}:{$password}"
			) );
		
		return $this;
	}

We'll update the documentation to have a non-framework example.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...