Skip to content

Commit e67d350

Browse files
Testing Token (#25)
* login file added token * added clerk function to receive a token * token get from clerk in frontend * remove clerk calling function in login.tsx file * remove clerk function in auth.tsx file * change bhalabhla passwoed to clerk dummy password * updated clerk_token_middileware * update login-page.tsx to center the login forms * updated auth.tsx --------- Co-authored-by: Bharani0012 <bharanitharan695@gmail.com>
1 parent 11c0fdb commit e67d350

3 files changed

Lines changed: 37 additions & 11 deletions

File tree

src/backend/base/langflow/services/auth/clerk_utils.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
import httpx
77
from fastapi import HTTPException, Request, status
8+
from fastapi.responses import JSONResponse
89
from jose import JWTError, jwk, jwt
910
from sqlmodel.ext.asyncio.session import AsyncSession
11+
from starlette.status import HTTP_401_UNAUTHORIZED
1012

1113
from langflow.logging.logger import logger
1214
from langflow.services.database.models.user import User, UserCreate
@@ -19,7 +21,7 @@
1921
_jwks_cache: dict[str, dict[str, Any]] = {}
2022

2123
# APIs that require Clerk token decoding in middleware
22-
PROTECTED_PATHS = ["/api/v1/users/"]
24+
PROTECTED_PATHS = ["/api/v1/users/","/api/v1/login"]
2325

2426

2527
async def _get_jwks(issuer: str) -> dict[str, Any]:
@@ -145,14 +147,27 @@ async def clerk_token_middleware(request: Request, call_next):
145147

146148
ctx_token: Token | None = None
147149
if settings.auth_settings.CLERK_AUTH_ENABLED and request.url.path in PROTECTED_PATHS:
150+
logger.info(f"Processing Clerk token for path: {request.url.path}")
148151
auth_header = request.headers.get("Authorization")
152+
153+
if not auth_header or not auth_header.startswith("Bearer "):
154+
logger.warning("Missing or malformed Authorization header for Clerk protected route.")
155+
return JSONResponse(
156+
status_code=HTTP_401_UNAUTHORIZED,
157+
content={"detail": "Authorization header with valid Bearer token required"},
158+
)
159+
149160
if auth_header and auth_header.startswith("Bearer "):
150161
token = auth_header[len("Bearer ") :]
151162
try:
152163
payload = await verify_clerk_token(token)
153164
ctx_token = auth_header_ctx.set(payload)
154165
except Exception as exc: # noqa: BLE001
155166
logger.warning(f"Failed to verify Clerk token: {exc}")
167+
return JSONResponse(
168+
status_code=HTTP_401_UNAUTHORIZED,
169+
content={"detail": "Invalid Clerk token"}
170+
)
156171

157172
try:
158173
return await call_next(request)

src/frontend/src/clerk/auth.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export async function backendLogin(username: string,token:string) {
6060
}).toString(),
6161
{
6262
headers: {
63+
Authorization: `Bearer ${token}`,
6364
"Content-Type": "application/x-www-form-urlencoded",
6465
},
6566
},

src/frontend/src/clerk/login-pages.tsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import { IS_CLERK_AUTH } from "@/clerk/auth";
77
export function ClerkLoginPage() {
88
return (
99
<SignedOut>
10-
<SignIn
11-
path="/login"
12-
routing="path"
13-
afterSignInUrl="/"
14-
/>
10+
<div style={centeredStyle}>
11+
<SignIn
12+
path="/login"
13+
routing="path"
14+
afterSignInUrl="/"
15+
/>
16+
</div>
1517
</SignedOut>
1618
);
1719
}
@@ -50,11 +52,13 @@ export function ClerkSignUpPage() {
5052

5153
return (
5254
<SignedOut>
53-
<SignUp
54-
path="/sign-up"
55-
routing="path"
56-
afterSignUpUrl="/login"
57-
/>
55+
<div style={centeredStyle}>
56+
<SignUp
57+
path="/sign-up"
58+
routing="path"
59+
afterSignUpUrl="/login"
60+
/>
61+
</div>
5862
</SignedOut>
5963
);
6064
}
@@ -68,3 +72,9 @@ export const LoginPage = IS_CLERK_AUTH ? ClerkLoginPage : OriginalLoginPage;
6872
export const SignUpPage = IS_CLERK_AUTH ? ClerkSignUpPage : OriginalSignUp;
6973
export const LoginAdminPage = IS_CLERK_AUTH ? ClerkLoginPage : OriginalLoginAdminPage;
7074

75+
const centeredStyle: React.CSSProperties = {
76+
display: "flex",
77+
justifyContent: "center",
78+
alignItems: "center",
79+
minHeight: "100vh",
80+
};

0 commit comments

Comments
 (0)