/// <reference types="node" />
import { IncomingMessage, ServerResponse } from 'http';
import { NextApiRequest, NextApiResponse } from 'next';
import { NextRequest, NextResponse } from 'next/server';
import { AuthorizationParameters } from '../auth0-session';
import { Session, SessionCache } from '../session';
import { GetClient } from '../auth0-session/client/abstract-client';
import { GetConfig } from '../config';
/**
 * After refresh handler for page router {@link AfterRefreshPageRoute} and app router {@link AfterRefreshAppRoute}.
 *
 * @category Server
 */
export type AfterRefresh = AfterRefreshPageRoute | AfterRefreshAppRoute;
/**
 * After refresh handler for page router.
 *
 * @category Server
 */
export type AfterRefreshPageRoute = (req: NextApiRequest | IncomingMessage, res: NextApiResponse | ServerResponse, session: Session) => Promise<Session> | Session;
/**
 * After refresh handler for app router.
 *
 * @category Server
 */
export type AfterRefreshAppRoute = (session: Session) => Promise<Session> | Session;
/**
 * Custom options to get an access token.
 *
 * @category Server
 */
export interface AccessTokenRequest {
    /**
     * A list of desired scopes for your access token.
     */
    scopes?: string[];
    /**
     * If set to `true`, a new access token will be requested with the refresh token grant, regardless of whether
     * the access token has expired or not.
     *
     * **IMPORTANT** You need to request the `offline_access` scope on login to get a refresh token
     * from Auth0.
     */
    refresh?: boolean;
    /**
     * When the access token request refreshes the tokens using the refresh grant the session is updated with new tokens.
     * Use this to modify the session after it is refreshed.
     * Usually used to keep updates in sync with the {@link AfterCallback} hook.
     *
     * @see also the {@link AfterRefetch} hook.
     *
     * @example Modify the session after refresh
     *
     * ```js
     * // pages/api/my-handler.js
     * import { getAccessToken } from '@auth0/nextjs-auth0';
     *
     * const afterRefresh = (req, res, session) => {
     *   session.user.customProperty = 'foo';
     *   delete session.idToken;
     *   return session;
     * };
     *
     * export default async function MyHandler(req, res) {
     *   const accessToken = await getAccessToken(req, res, {
     *     refresh: true,
     *     afterRefresh,
     *   });
     * };
     * ```
     */
    afterRefresh?: AfterRefresh;
    /**
     * This is useful for sending custom query parameters in the body of the refresh grant request for use in rules.
     */
    authorizationParams?: Partial<AuthorizationParameters>;
}
/**
 * Response from requesting an access token.
 *
 * @category Server
 */
export interface GetAccessTokenResult {
    /**
     * Access token returned from the token cache.
     */
    accessToken?: string | undefined;
}
/**
 * Get an access token to access an external API from the server.
 *
 * **In the App Router:**
 *
 * In a route handler:
 *
 * ```js
 * // app/my-api/route.js
 * import { NextResponse } from 'next/server';
 * import { getAccessToken } from '@auth0/nextjs-auth0';
 *
 * export async function GET() {
 *   const { accessToken } = await getAccessToken();
 *   return NextResponse.json({ foo: 'bar' });
 * }
 *
 * // Or, it's slightly more efficient to use the `req`, `res` args if you're
 * // using another part of the SDK like `withApiAuthRequired` or `getSession`.
 * import { NextResponse } from 'next/server';
 * import { getAccessToken, withApiAuthRequired } from '@auth0/nextjs-auth0';
 *
 * const GET = withApiAuthRequired(async function GET(req) {
 *   const res = new NextResponse();
 *   const { accessToken } = await getAccessToken(req, res);
 *   return NextResponse.json({ foo: 'bar' }, res);
 * });
 *
 * export { GET };
 * ```
 *
 * In a page or React Server Component:
 *
 * ```js
 * // app/my-page/page.js
 * import { getAccessToken } from '@auth0/nextjs-auth0';
 *
 * export default async function MyPage({ params, searchParams }) {
 *   const { accessToken } = await getAccessToken();
 *   return <h1>My Page</h1>;
 * }
 * ```
 *
 * **Note:** You can't write to the cookie in a React Server Component, so if
 * the access token is refreshed, it won't be persisted in the session.
 *
 * You can also get the access token in a page or route in the Edge Runtime:
 *
 * ```js
 * // app/my-api/route.js
 * import { NextResponse } from 'next/server';
 * import { getAccessToken } from '@auth0/nextjs-auth0/edge'; // Note the /edge import
 *
 * export async function GET() {
 *   const { accessToken } = await getAccessToken();
 *   return NextResponse.json({ foo: 'bar' });
 * }
 *
 * export const runtime = 'edge';
 * ```
 *
 * **Note:** The Edge runtime features are only supported in the App Router.
 *
 * **In the Page Router:**
 *
 * In an API handler:
 *
 * ```js
 * // pages/api/my-api.js
 * import { getAccessToken } from '@auth0/nextjs-auth0';
 *
 * export default async function MyApi(req, res) {
 *   const { accessToken } = await getAccessToken(req, res);
 *   res.status(200).json({ name: 'John Doe' });
 * }
 * ```
 *
 * In a page:
 *
 * ```js
 * // pages/my-page.js
 * import { getAccessToken } from '@auth0/nextjs-auth0';
 *
 * export default function About() {
 *   return <div>About</div>;
 * }
 *
 * export async function getServerSideProps(ctx) {
 *   const { accessToken } = await getAccessToken(ctx.req, ctx.res);
 *   return { props: { foo: 'bar' } };
 * }
 * ```
 *
 * **In middleware:**
 *
 * ```js
 * import { NextResponse } from 'next/server';
 * import { getAccessToken } from '@auth0/nextjs-auth0/edge'; // Note the /edge import

 *
 * export async function middleware(req) {
 *   const res = new NextResponse();
 *   const { accessToken } = await getAccessToken(req, res);
 *   return NextResponse.redirect(new URL('/bar', request.url), res);
 * }
 *
 * export const config = {
 *   matcher: '/foo',
 * };
 * ```
 *
 * @throws {@link AccessTokenError}
 *
 * @category Server
 */
export type GetAccessToken = (...args: [IncomingMessage, ServerResponse, AccessTokenRequest?] | [NextApiRequest, NextApiResponse, AccessTokenRequest?] | [NextRequest, NextResponse, AccessTokenRequest?] | [AccessTokenRequest?]) => Promise<GetAccessTokenResult>;
/**
 * @ignore
 */
export default function accessTokenFactory(getConfig: GetConfig, getClient: GetClient, sessionCache: SessionCache): GetAccessToken;
//# sourceMappingURL=get-access-token.d.ts.map