Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 163 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"main": "build/index.js",
"types": "build/index.d.ts",
"dependencies": {
"jsonwebtoken": "^9.0.2",
"jwks-rsa": "^3.2.0",
"oauth2-server": "^3.1.1"
},
"overrides_comment": "We override type-is as is conflicting with body-parser",
Expand Down
9 changes: 9 additions & 0 deletions src/lib/oauth2-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from 'oauth2-server';

import type { NextFunction, Request, Response } from 'express';
import { SSO_PASSWORD } from './utils';

// We must save both tokens, as by logout we must revoke both
export interface InternalStorageToken {
Expand Down Expand Up @@ -97,6 +98,7 @@ export class OAuth2Model implements RefreshTokenModel {

authorize = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
const _req: Request & { user?: string } = req;

// Check if the user is logged in
if (!_req.user) {
// If authenticated by token in query like /blabla?token=ACCESS_TOKEN
Expand Down Expand Up @@ -188,6 +190,13 @@ export class OAuth2Model implements RefreshTokenModel {
* Get user.
*/
getUser = async (username: string, password: string): Promise<User | Falsey> => {
if (password === SSO_PASSWORD) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I haven't found a clean solution while sticking to the oauth2-server module, hence I used this approach which I don't think is perfect at all.

this.adapter.log.debug(`SSO login as ${username}`);
return {
id: username,
};
}

const now = Date.now();
if (this.bruteForce[username]?.errors > 4) {
let minutes = now - this.bruteForce[username].time;
Expand Down
Loading