Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bearer Access Token Authentication does not work. #825

Open
ankitparmar14190 opened this issue Dec 10, 2024 · 1 comment
Open

Bearer Access Token Authentication does not work. #825

ankitparmar14190 opened this issue Dec 10, 2024 · 1 comment
Labels
question Question asked by a user triage A new issue that needs triage

Comments

@ankitparmar14190
Copy link

Package

next-drupal (NPM package)

Ask the question

Access Token does not work.

I have used Access Token authentication to fetch data with secure API but getting below error.
Error: Failed to fetch JSON:API index at <base_url>/jsonapi

Could you please help me over here? Am I missing something to add here?

Note:- This is working without authentication. But we enable authentication it does not work. Token is generating correct. I tried with postman.

Here is my code

const getToken = await fetchToken();

  const drupal = new DrupalClient(baseUrl, {
    auth: {
      access_token: getToken.access_token,
      token_type: getToken.token_type,
      expires_in: getToken.token_type
    },
  });
  
  const articles = await drupal.getResourceCollection("node--news", {
    withAuth: {
      access_token: getToken.access_token,
      token_type: getToken.token_type,
      expires_in: getToken.expires_in
    },
  });
@ankitparmar14190 ankitparmar14190 added question Question asked by a user triage A new issue that needs triage labels Dec 10, 2024
@ankitparmar14190
Copy link
Author

ankitparmar14190 commented Dec 13, 2024

Just want to inform you like I tried other test cases to fetch data using token but it does not work. Is there any solution?

Test Case 1: Use Access Token

  const drupal = new DrupalClient(baseUrl, {
    fetch: (url, options) => {
      options.headers = {
        ...options.headers = {
          Authorization: `Bearer ${getToken.access_token}`
        }
      };
      return fetch(url, options)
    }
  });

  'тип Error: Failed to fetch JSON:API index at <baseurl>/jsonapi - Unexpected token '<', "<!DOCTYPE "... is not valid JSON'

Test Case 2:

  const drupal = new DrupalClient(baseUrl, {
      auth: {
        access_token: getToken.access_token,
        token_type: getToken.token_type,
        expires_in: getToken.expires_in,
      },
  });

 'тип Error: Failed to fetch JSON:API index at<baseurl>/jsonapi - Unexpected token '<', "<!DOCTYPE "... is not valid JSON'

Test Case 3

  const drupal = new DrupalClient(baseUrl, {
      auth: {
        token: {
          access_token: getToken.access_token,
          token_type: getToken.token_type,
          expires_in: getToken.expires_in,
        }
      },
  });

`тип Error: 'clientId' and 'clientSecret' are required for auth. See https://next-drupal.org/docs/client/auth
    at BlogPage (./app/mynews/page.jsx:74:20)`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question asked by a user triage A new issue that needs triage
Projects
None yet
Development

No branches or pull requests

1 participant