Skip to content

feat: OAuth - #202

Open
cjs8487 wants to merge 25 commits into
mainfrom
oauth
Open

feat: OAuth#202
cjs8487 wants to merge 25 commits into
mainfrom
oauth

Conversation

@cjs8487

@cjs8487 cjs8487 commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Implements the OAuth2 spec in the PlayBingo API, allowing third party components to authenticate requests on behalf of users.

This implementation represents multiple features

  • Developer user flag: users can now be flagged as developers, which grants access to the new Developer Portal, where OAuth clients can be managed
  • OAuth client management: Developer users can create and manage OAuth clients from the developer portal. This is where they can manage their redirect uris, reset client secret, view client id, etc.
  • Authorization flow: located at /authorize this new page represents the permission check for OAuth applications looking to get permissions from a user. This checkpoint is designed to help make sure the correct user is authenticated, the user is aware of what permissions they are granting, and be a stop gap in an otherwise automatic flow when users are logged in
  • Token endpoint: The token endpoint is how third party applications exchange credentials for an OAuth token representing the security of a particular user. The endpoint supports code and refresh token exchanges, code exchanges being the primary mechanism for obtaining new tokens and refresh token exchanges being the mechanism by which applications can maintain access for a particular token over long periods.

Security

Whenever the Authorization header is present on a request, the session will be converted to an OAuth session (even if the token is invalid or malformed - this prevents session poisoning/leaking or the ability to maintain access past revocation/expiration). If the token is successfully verified, the user is re-added to the session, otherwise it is cleared. This minimizes the security relevant change footprint of this in terms of existing checks.

@cjs8487
cjs8487 requested a review from Floha258 June 4, 2026 02:36
Comment thread api/src/main.ts Outdated
Comment on lines +236 to +248
oauth.post('/client', async (req, res) => {
if (!req.session.user) {
res.sendStatus(401);
return;
}
const { name } = req.body;
if (!name) {
res.status(400).send('Missing client application name');
return;
}
const client = await createOAuthClient(name, req.session.user);
res.status(201).json(client);
});

@Floha258 Floha258 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be blind but I didn't see any form of authentication for some of the oath routes.
Also is it possible that you never actually tell the main Express app to use the oauth router?

return;
}
if (!client.redirectUris.includes(redirectUri)) {
res.status(400).send('Invalid redirect uri');

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a 403?

Comment on lines +249 to +280
oauth
.route('/:id')
.get(async (req, res) => {
const { id } = req.params;
const client = await getClient(id);
if (!client) {
res.sendStatus(404);
return;
}
res.json(client);
})
.delete(async (req, res) => {
const { id } = req.params;
await deleteClient(id);
res.sendStatus(200);
})
.post(async (req, res) => {
const { id } = req.params;
const { name, redirects } = req.body;
if (!name && !redirects) {
res.sendStatus(400);
return;
}
const client = await updateClient(id, name, redirects);
res.status(200).json(client);
});

oauth.post('/:id/resetSecret', async (req, res) => {
const { id } = req.params;
const newSecret = await resetClientSecret(id);
res.status(200).json(newSecret);
});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I missing some form of authorization in here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants