code
param that I can exchange with access token to authenticate my app on behalf of users? In my cookies by default with Kinde, I see access_token
refresh_token
but I'm not sure they can be used as an authorization header on Github API calls. code
parameter, which you can exchange for an access token to authenticate your app on behalf of users. This process is part of the standard OAuth 2.0 authorization code grant flow, which is used by Kinde for authentication with external providers like GitHub.code
parameter in the URL. You need to capture this code and exchange it for an access token by making a POST request to the GitHub token endpoint. This access token can then be used as an authorization header in GitHub API calls.code
parameter from the query string.code
for an access token. You'll need to include your GitHub app's client ID and client secret in this request.access_token
and refresh_token
you see in cookies are related to Kinde's authentication process and are not directly usable for GitHub API calls. You need to follow the OAuth flow to obtain a GitHub-specific access token.code
parameter from the callback URL's query string in your application, you will need to implement logic within your callback route handler. When Kinde redirects the user back to your application after authentication, the URL will include the code
parameter as a query string. Here's a general approach to handle this:code
parameter along with any others you've specified, such as state
.code
parameter.code
Parameter: Within your route handler, extract the code
parameter from the query string. The exact method to do this will depend on the backend framework or library you are using. For example, in Express.js for Node.js, you can access query parameters using req.query.code
.code
for an Access Token: Once you have the code
, you need to make a POST request to the Kinde token endpoint (https://<your_kinde_subdomain>.kinde.com/oauth/token
) to exchange it for an access token. Include parameters such as client_id
, client_secret
, redirect_uri
, grant_type
(set to authorization_code
), and the code
you just captured.app.get('/api/auth/kinde_callback', async (req, res) => { const code = req.query.code; if (code) { try { // Exchange the code for an access token const response = await axios.post('https://<your_kinde_subdomain>.kinde.com/oauth/token', { client_id: '<your_kinde_client_id>', client_secret: '<your_kinde_client_secret>', grant_type: 'authorization_code', redirect_uri: '<your_app_redirect_url>', code: code, }); const accessToken = response.data.access_token; // Use the access token as needed } catch (error) { console.error('Error exchanging code for token:', error); // Handle error } } else { // Handle the case where the code parameter is missing } });
fetch
API to make external HTTP requests. Here's a generic example that can be adapted for Next.js 14, assuming similar patterns hold:// pages/api/example.js export default async function handler(req, res) { // Example fetch request to an external API const response = await fetch('https://api.example.com/data', { method: 'GET', // or 'POST' headers: { 'Content-Type': 'application/json', // Additional headers }, // body: JSON.stringify(data), // if method is POST }); if (!response.ok) { // Handle response error res.status(response.status).json({ error: 'Failed to fetch data' }); return; } const data = await response.json(); // Respond with fetched data res.status(200).json(data); }
fetch
request to an external API, processes the response, and returns the data to the client. Remember to replace 'https://api.example.com/data'
with the actual URL you intend to fetch data from.code
parameter for an access token.