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

How to get bearer access token to use it in apis #634

Closed
tiwarivijay123 opened this issue Apr 4, 2022 · 7 comments
Closed

How to get bearer access token to use it in apis #634

tiwarivijay123 opened this issue Apr 4, 2022 · 7 comments
Labels
question Further information is requested

Comments

@tiwarivijay123
Copy link

import { getAccessToken, withApiAuthRequired } from '@auth0/nextjs-auth0';

export default withApiAuthRequired(async function products(req, res) {
  // If your Access Token is expired and you have a Refresh Token
  // `getAccessToken` will fetch you a new one using the `refresh_token` grant
  const { accessToken } = await getAccessToken(req, res, {
    scopes: ['read:products']
  });
  const response = await fetch('https://api.example.com/products', {
    headers: {
      Authorization: `Bearer ${accessToken}`
    }
  });
  const products = await response.json();
  res.status(200).json(products);
});

I'm using this code to get access token but not getting any success even I'm little bit confused how to use this code in other files to get token

@adamjmcgrath
Copy link
Contributor

Hi @tiwarivijay123

The code you've shared is from our examples page and is correct.

What have you tried and how is it not working? Please share a running example, HAR files or at least some code you've written and details of what errors you're getting

@adamjmcgrath adamjmcgrath added the question Further information is requested label Apr 5, 2022
@tiwarivijay123
Copy link
Author

@adamjmcgrath I found this code from SDK , but let me know how I can get token in client side app and how to use this ?

@adamjmcgrath
Copy link
Contributor

Hi @tiwarivijay123

how I can get token in client side app and how to use this ?

This question has been answered in #358

@tiwarivijay123
Copy link
Author

My question's answer is not there @adamjmcgrath. I'm making web app using next JS, Is there any hooks to get access token ? my all authentication process has been done just I have issue with access token I'm unable to get that if you can provide me code of to fetch access token that would be great for me..

@Widcket
Copy link
Contributor

Widcket commented Apr 8, 2022

Hi @tiwarivijay123, I believe #358 (comment) answers your question. Also please check out https://github.com/auth0/nextjs-auth0#comparison-with-the-auth0-react-sdk.

@tiwarivijay123
Copy link
Author

@Widcket can you share code that returns access token ?

@Widcket
Copy link
Contributor

Widcket commented Apr 12, 2022

Closing as I believe your question has been answered.
For general usage questions please refer to the Auth0 Community forums, or raise a support ticket.

@Widcket Widcket closed this as completed Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants