Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Drop expiry from internal only JWT #4207

Merged
merged 1 commit into from
Jan 25, 2025
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
5 changes: 3 additions & 2 deletions api.planx.uk/modules/auth/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { $api } from "../../client/index.js";
import type { User, Role } from "@opensystemslab/planx-core/types";
import type { HasuraClaims, JWTData } from "./types.js";

export const buildJWT = async (email: string): Promise<string | undefined> => {
export const buildUserJWT = async (
email: string,
): Promise<string | undefined> => {
const user = await $api.user.getByEmail(email);
if (!user) return;

Expand All @@ -28,7 +30,6 @@ export const buildJWTForAPIRole = () =>
},
},
process.env.JWT_SECRET!,
{ expiresIn: "24h" },
);

const generateHasuraClaimsForUser = (user: User): HasuraClaims => ({
Expand Down
4 changes: 2 additions & 2 deletions api.planx.uk/modules/auth/strategy/google.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Strategy as GoogleStrategy } from "passport-google-oauth20";
import { buildJWT } from "../service.js";
import { buildUserJWT } from "../service.js";

export const googleStrategy = new GoogleStrategy(
{
Expand All @@ -11,13 +11,13 @@
const { email } = profile._json;
if (!email) throw Error("Unable to authenticate without email");

const jwt = await buildJWT(email);
const jwt = await buildUserJWT(email);

if (!jwt) {
return done({
status: 404,
message: `User (${email}) not found. Do you need to log in to a different Google Account?`,
} as any);

Check warning on line 20 in api.planx.uk/modules/auth/strategy/google.ts

View workflow job for this annotation

GitHub Actions / Run API Tests

Unexpected any. Specify a different type
}

done(null, { jwt });
Expand Down
4 changes: 2 additions & 2 deletions api.planx.uk/modules/auth/strategy/microsoft-oidc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
StrategyVerifyCallbackReq,
} from "openid-client";
import { Strategy } from "openid-client";
import { buildJWT } from "../service.js";
import { buildUserJWT } from "../service.js";

export const MICROSOFT_OPENID_CONFIG_URL =
"https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration";
Expand Down Expand Up @@ -70,7 +70,7 @@ const verifyCallback: StrategyVerifyCallbackReq<Express.User> = async (
return done(new Error("Unable to authenticate without email"));
}

const jwt = await buildJWT(email);
const jwt = await buildUserJWT(email);
if (!jwt) {
return done({
status: 404,
Expand Down
Loading