© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Cloudflare DevelopersCD
Cloudflare Developers•2y ago•
24 replies
sanner

OATUH Cloudflare Pages

I was developing trying to implement github oauth on cloudfare pages using a beta branch. the production branch is define as another branch and the production branch contains the main url. It works locally but not on cloudflare pages

my oauth flow looks like this at the moment

export async function GET(context: APIContext): Promise<Response> {
    const state = generateState();
    const url = await github.createAuthorizationURL(state);

    context.cookies.set("github_oauth_state", state, {
        path: "/",
        secure: DEPLOYED_ENV,
        httpOnly: true,
        maxAge: 60 * 10,
        sameSite: "lax"
    });

    const responseBody = {
        url: url.toString()
    };
    const response = new Response(JSON.stringify(responseBody), {
    status: 200,
        headers: {
            "content-type": "application/json",
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "GET, PUT, POST, DELETE, OPTIONS",
            "Access-Control-Allow-Headers": "*"
        }
    });
    return response;
}
export async function GET(context: APIContext): Promise<Response> {
    const state = generateState();
    const url = await github.createAuthorizationURL(state);

    context.cookies.set("github_oauth_state", state, {
        path: "/",
        secure: DEPLOYED_ENV,
        httpOnly: true,
        maxAge: 60 * 10,
        sameSite: "lax"
    });

    const responseBody = {
        url: url.toString()
    };
    const response = new Response(JSON.stringify(responseBody), {
    status: 200,
        headers: {
            "content-type": "application/json",
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "GET, PUT, POST, DELETE, OPTIONS",
            "Access-Control-Allow-Headers": "*"
        }
    });
    return response;
}
Cloudflare Developers banner
Cloudflare DevelopersJoin
Welcome to the official Cloudflare Developers server. Here you can ask for help and stay updated with the latest news
85,042Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

cloudflare pages
Cloudflare DevelopersCDCloudflare Developers / pages-help
2y ago
Cloudflare Pages Error
Cloudflare DevelopersCDCloudflare Developers / pages-help
2y ago
Supabase + Cloudflare pages?
Cloudflare DevelopersCDCloudflare Developers / pages-help
3y ago
Slow Cloudflare Pages
Cloudflare DevelopersCDCloudflare Developers / pages-help
3y ago