Spaces:
Sleeping
Sleeping
Andrew
commited on
Commit
·
f941835
1
Parent(s):
e27f529
feat(auth): add HF token capture to generic OIDC callback
Browse files
src/routes/login/callback/+server.ts
CHANGED
|
@@ -61,12 +61,27 @@ export async function GET({ url, locals, cookies, request, getClientAddress }) {
|
|
| 61 |
throw error(403, "Invalid or expired CSRF token");
|
| 62 |
}
|
| 63 |
|
| 64 |
-
const { userData } = await getOIDCUserData(
|
| 65 |
{ redirectURI: validatedToken.redirectUrl },
|
| 66 |
code,
|
| 67 |
iss
|
| 68 |
);
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
// Filter by allowed user emails or domains
|
| 71 |
if (allowedUserEmails.length > 0 || allowedUserDomains.length > 0) {
|
| 72 |
if (!userData.email) {
|
|
@@ -92,6 +107,8 @@ export async function GET({ url, locals, cookies, request, getClientAddress }) {
|
|
| 92 |
cookies,
|
| 93 |
userAgent: request.headers.get("user-agent") ?? undefined,
|
| 94 |
ip: getClientAddress(),
|
|
|
|
|
|
|
| 95 |
});
|
| 96 |
|
| 97 |
return redirect(302, `${base}/`);
|
|
|
|
| 61 |
throw error(403, "Invalid or expired CSRF token");
|
| 62 |
}
|
| 63 |
|
| 64 |
+
const { token, userData } = await getOIDCUserData(
|
| 65 |
{ redirectURI: validatedToken.redirectUrl },
|
| 66 |
code,
|
| 67 |
iss
|
| 68 |
);
|
| 69 |
|
| 70 |
+
const tokenIssuer = (() => {
|
| 71 |
+
if (typeof token.issuer === "string") return token.issuer;
|
| 72 |
+
const claims = typeof token.claims === "function" ? token.claims() : undefined;
|
| 73 |
+
if (claims && typeof claims.iss === "string") return claims.iss;
|
| 74 |
+
if (typeof token.iss === "string") return token.iss;
|
| 75 |
+
return "";
|
| 76 |
+
})();
|
| 77 |
+
|
| 78 |
+
const issuerCandidate = [iss, tokenIssuer, config.OPENID_PROVIDER_URL]
|
| 79 |
+
.filter((value): value is string => typeof value === "string")
|
| 80 |
+
.map((value) => value.toLowerCase())
|
| 81 |
+
.join(" ");
|
| 82 |
+
|
| 83 |
+
const isHuggingFaceProvider = issuerCandidate.includes("huggingface.co");
|
| 84 |
+
|
| 85 |
// Filter by allowed user emails or domains
|
| 86 |
if (allowedUserEmails.length > 0 || allowedUserDomains.length > 0) {
|
| 87 |
if (!userData.email) {
|
|
|
|
| 107 |
cookies,
|
| 108 |
userAgent: request.headers.get("user-agent") ?? undefined,
|
| 109 |
ip: getClientAddress(),
|
| 110 |
+
authProvider: isHuggingFaceProvider ? "huggingface" : "oidc",
|
| 111 |
+
accessToken: isHuggingFaceProvider ? (token.access_token ?? undefined) : undefined,
|
| 112 |
});
|
| 113 |
|
| 114 |
return redirect(302, `${base}/`);
|