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

swagger fixups #252

Merged
merged 6 commits into from
Apr 23, 2024
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
2 changes: 1 addition & 1 deletion spec/oas_v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ info:
name: MIT
url: https://opensource.org/licenses/MIT
servers:
- url: vote.optimisim.io/api/v1
- url: https://vote.optimism.io/api/v1
description: Base URL for optimism production
security:
- bearerAuth: []
Expand Down
13 changes: 10 additions & 3 deletions src/app/lib/middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { validate as validateUuid } from "uuid";
let prismaModule: any;

const HASH_FN = "sha256";
const REASON_NO_TOKEN = "No token provided in 'authorization' header";
const REASON_NO_TOKEN = "No token provided in 'Authorization' header";
const REASON_INVALID_API_KEY = "Invalid API Key";
const REASON_DISABLED_USER = "User disabled";

Expand All @@ -15,8 +15,15 @@ export type AuthResponse = {
reason?: string;
};

export function extractBearerToken(token?: string | null) {
if (token && token.split(" ")[0] === "Bearer") {
return token.split(" ")[1];
}
return null;
}

export function hasApiKey(request: NextRequest): AuthResponse {
const token = request.headers.get("authorization");
const token = extractBearerToken(request.headers.get("Authorization"));
let authResponse: AuthResponse = { authenticated: true, reason: "" };

if (!token) {
Expand Down Expand Up @@ -52,7 +59,7 @@ export async function authenticateApiUser(

let authResponse: AuthResponse = hasApiKey(request);

const key = request.headers.get("authorization");
const key = extractBearerToken(request.headers.get("Authorization"));

if (!key) {
return authResponse;
Expand Down
Loading