Spaces:
Paused
Paused
add alternative callback url (#766)
Browse filesCo-authored-by: Kevin CATHALY <alakme@kevins-mbp.home>
Co-authored-by: Nathan Sarrazin <sarrazin.nathan@gmail.com>
- .env +3 -1
- .env.template +4 -0
- src/routes/login/+page.server.ts +13 -2
.env
CHANGED
|
@@ -130,4 +130,6 @@ EXPOSE_API=true
|
|
| 130 |
# PUBLIC_APP_DATA_SHARING=1
|
| 131 |
# PUBLIC_APP_DISCLAIMER=1
|
| 132 |
|
| 133 |
-
ENABLE_ASSISTANTS=false #set to true to enable assistants feature
|
|
|
|
|
|
|
|
|
| 130 |
# PUBLIC_APP_DATA_SHARING=1
|
| 131 |
# PUBLIC_APP_DISCLAIMER=1
|
| 132 |
|
| 133 |
+
ENABLE_ASSISTANTS=false #set to true to enable assistants feature
|
| 134 |
+
|
| 135 |
+
ALTERNATIVE_REDIRECT_URLS=`[]` #valide alternative redirect URL for OAuth
|
.env.template
CHANGED
|
@@ -243,3 +243,7 @@ PUBLIC_PLAUSIBLE_SCRIPT_URL="/js/script.js"
|
|
| 243 |
|
| 244 |
ENABLE_ASSISTANTS=true
|
| 245 |
EXPOSE_API=true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
|
| 244 |
ENABLE_ASSISTANTS=true
|
| 245 |
EXPOSE_API=true
|
| 246 |
+
|
| 247 |
+
ALTERNATIVE_REDIRECT_URLS=`[
|
| 248 |
+
huggingchat://login/callback
|
| 249 |
+
]`
|
src/routes/login/+page.server.ts
CHANGED
|
@@ -1,13 +1,24 @@
|
|
| 1 |
import { redirect } from "@sveltejs/kit";
|
| 2 |
import { getOIDCAuthorizationUrl } from "$lib/server/auth";
|
| 3 |
import { base } from "$app/paths";
|
|
|
|
| 4 |
|
| 5 |
export const actions = {
|
| 6 |
async default({ url, locals, request }) {
|
| 7 |
-
// TODO: Handle errors if provider is not responding
|
| 8 |
const referer = request.headers.get("referer");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
const authorizationUrl = await getOIDCAuthorizationUrl(
|
| 10 |
-
{ redirectURI
|
| 11 |
{ sessionId: locals.sessionId }
|
| 12 |
);
|
| 13 |
|
|
|
|
| 1 |
import { redirect } from "@sveltejs/kit";
|
| 2 |
import { getOIDCAuthorizationUrl } from "$lib/server/auth";
|
| 3 |
import { base } from "$app/paths";
|
| 4 |
+
import { ALTERNATIVE_REDIRECT_URLS } from "$env/static/private";
|
| 5 |
|
| 6 |
export const actions = {
|
| 7 |
async default({ url, locals, request }) {
|
|
|
|
| 8 |
const referer = request.headers.get("referer");
|
| 9 |
+
let redirectURI = `${(referer ? new URL(referer) : url).origin}${base}/login/callback`;
|
| 10 |
+
|
| 11 |
+
// TODO: Handle errors if provider is not responding
|
| 12 |
+
|
| 13 |
+
if (url.searchParams.has("callback")) {
|
| 14 |
+
const callback = url.searchParams.get("callback") || redirectURI;
|
| 15 |
+
if (ALTERNATIVE_REDIRECT_URLS.includes(callback)) {
|
| 16 |
+
redirectURI = callback;
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
const authorizationUrl = await getOIDCAuthorizationUrl(
|
| 21 |
+
{ redirectURI },
|
| 22 |
{ sessionId: locals.sessionId }
|
| 23 |
);
|
| 24 |
|