Skip to content

Commit a323bf6

Browse files
fix(app): make Modrinth account SSO logins from the app work (#4345)
1 parent e2f07a7 commit a323bf6

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

apps/frontend/src/composables/auth.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export const getAuthUrl = (provider, redirect = '/dashboard') => {
109109
const route = useNativeRoute()
110110

111111
const fullURL = route.query.launcher
112-
? 'https://launcher-files.modrinth.com'
112+
? getLauncherRedirectUrl(route)
113113
: `${config.public.siteUrl}/auth/sign-in?redirect=${redirect}`
114114

115115
return `${config.public.apiBaseUrl}auth/init?provider=${provider}&url=${encodeURIComponent(fullURL)}`
@@ -131,3 +131,12 @@ export const removeAuthProvider = async (provider) => {
131131

132132
stopLoading()
133133
}
134+
135+
export const getLauncherRedirectUrl = (route) => {
136+
const usesLocalhostRedirectionScheme =
137+
['4', '6'].includes(route.query.ipver) && Number(route.query.port) < 65536
138+
139+
return usesLocalhostRedirectionScheme
140+
? `http://${route.query.ipver === '4' ? '127.0.0.1' : '[::1]'}:${route.query.port}`
141+
: `https://launcher-files.modrinth.com`
142+
}

apps/frontend/src/pages/auth/sign-in.vue

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ import { commonMessages, injectNotificationManager } from '@modrinth/ui'
144144
import { IntlFormatted } from '@vintl/vintl/components'
145145
146146
import HCaptcha from '@/components/ui/HCaptcha.vue'
147-
import { getAuthUrl } from '@/composables/auth.js'
147+
import { getAuthUrl, getLauncherRedirectUrl } from '@/composables/auth.js'
148148
149149
const { addNotification } = injectNotificationManager()
150150
const { formatMessage } = useVIntl()
@@ -275,26 +275,21 @@ async function finishSignIn(token) {
275275
token = auth.value.token
276276
}
277277
278-
const usesLocalhostRedirectionScheme =
279-
['4', '6'].includes(route.query.ipver) && Number(route.query.port) < 65536
278+
const redirectUrl = `${getLauncherRedirectUrl(route)}/?code=${token}`
280279
281-
const redirectUrl = usesLocalhostRedirectionScheme
282-
? `http://${route.query.ipver === '4' ? '127.0.0.1' : '[::1]'}:${route.query.port}/?code=${token}`
283-
: `https://launcher-files.modrinth.com/?code=${token}`
284-
285-
if (usesLocalhostRedirectionScheme) {
286-
// When using this redirection scheme, the auth token is very visible in the URL to the user.
280+
if (redirectUrl.startsWith('https://launcher-files.modrinth.com/')) {
281+
await navigateTo(redirectUrl, {
282+
external: true,
283+
})
284+
} else {
285+
// When redirecting to localhost, the auth token is very visible in the URL to the user.
287286
// While we could make it harder to find with a POST request, such is security by obscurity:
288287
// the user and other applications would still be able to sniff the token in the request body.
289288
// So, to make the UX a little better by not changing the displayed URL, while keeping the
290289
// token hidden from very casual observation and keeping the protocol as close to OAuth's
291290
// standard flows as possible, let's execute the redirect within an iframe that visually
292291
// covers the entire page.
293292
subtleLauncherRedirectUri.value = redirectUrl
294-
} else {
295-
await navigateTo(redirectUrl, {
296-
external: true,
297-
})
298293
}
299294
300295
return

apps/labrinth/.env.docker-compose

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ RATE_LIMIT_IGNORE_IPS='["127.0.0.1"]'
5151

5252
WHITELISTED_MODPACK_DOMAINS='["cdn.modrinth.com", "github.com", "raw.githubusercontent.com"]'
5353

54-
ALLOWED_CALLBACK_URLS='["localhost", ".modrinth.com", "127.0.0.1"]'
54+
ALLOWED_CALLBACK_URLS='["localhost", ".modrinth.com", "127.0.0.1", "[::1]"]'
5555

5656
GITHUB_CLIENT_ID=none
5757
GITHUB_CLIENT_SECRET=none

apps/labrinth/.env.local

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ RATE_LIMIT_IGNORE_IPS='["127.0.0.1"]'
5151

5252
WHITELISTED_MODPACK_DOMAINS='["cdn.modrinth.com", "github.com", "raw.githubusercontent.com"]'
5353

54-
ALLOWED_CALLBACK_URLS='["localhost", ".modrinth.com", "127.0.0.1"]'
54+
ALLOWED_CALLBACK_URLS='["localhost", ".modrinth.com", "127.0.0.1", "[::1]"]'
5555

5656
GITHUB_CLIENT_ID=none
5757
GITHUB_CLIENT_SECRET=none

0 commit comments

Comments
 (0)