Erisa / discord-oidc-worker

Sign into Discord on Cloudflare Access, powered by Cloudflare Workers!
MIT License
156 stars 24 forks source link
cloudflare-access cloudflare-workers discord oauth2 oidc-provider workers zero-trust

Discord OIDC Provider for Cloudflare Access

Simply put: Allows you to authorise with Cloudflare Access using your Discord account via a Cloudflare Worker. Wraps OIDC around the Discord OAuth2 API to achieve this, storing signing keys in KV.

Process flow was inspired by kimcore/discord-oidc but rewritten entirely for Cloudflare Workers and Hono.

Some ideas were also taken from eidam/cf-access-workers-oidc.

Show them some love!

Setup

Requirements:

Steps:

Usage

Usage with roles

Example config for a roles setup:

{
    "clientId": "1056005449054429204",
    "clientSecret": "aaaaaaaaaaaaa",
    "redirectURL": "https://erisa.cloudflareaccess.com/cdn-cgi/access/callback",
    "serversToCheckRolesFor": [
        "438781053675634713"
    ]
}

Examples

My setup, as an example:

To use this in a policy, simply enable it as an Identity provider in your Access application and then create a rule using OIDC Claims and the relevant claim above. Make sure the claim has been added to your provider in the steps above.

With roles:

This example would allow me to access the application if I was myself on Discord or if I was a member of a specific server:

Security

If you find a security vulnerability in this repository, do NOT create an Issue or Pull Request. Please contact me through email or message (There are links on my GitHub profile). If you create an issue for an active security vulnerability I will save the information and delete the issue.

Alternatively, you can try out a new GitHub feature for Security Advisories: https://github.com/Erisa/discord-oidc-worker/security