Skip to content
This repository was archived by the owner on Aug 21, 2024. It is now read-only.

Commit af080a2

Browse files
committed
Added support for cross-domain login.
For multi-domain setups, having to log in on each different domain is annoying. This saves the user's login information in the 'root' domain of the deployment, and on all domains sources the login credentials from an iframe running in the root domain using postMessage. This only gets skipped if a user has expressly denied cross-domain sharing of their login information, in which case localStorage will be used as the source for login credentials. The iframe loads a new non-vite page in client/public, and does so in the root domain. Some user authorization flow is required on most browsers to enable this, using the requestStorageAccess API. A new backend service, allowed-domains, takes in a domain on a query paramter and returns true if that domain is part of the deployment, and a 204 if not. By default this just returns the root domain, but this is extensible via projects' hooks to add other domains to the allowed list. It can also just be passed a variable isAllowed from a hook if fetching all domains would be cumbersome, and simply querying whether the domain is in a table would be simpler. The accessor iframe uses the response to determine whether to even attempt to access the cookies or prompt the user with requestStorageAccess.
1 parent 3bb6b5c commit af080a2

25 files changed

Lines changed: 686 additions & 102 deletions

File tree

β€ŽDockerfileβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ ARG VITE_READY_PLAYER_ME_URL
6262
ARG VITE_DISABLE_LOG
6363
ARG VITE_AVATURN_URL
6464
ARG VITE_AVATURN_API
65+
ARG VITE_FEATHERS_STORE_KEY
6566
ENV MYSQL_HOST=$MYSQL_HOST
6667
ENV MYSQL_PORT=$MYSQL_PORT
6768
ENV MYSQL_USER=$MYSQL_USER
@@ -85,6 +86,7 @@ ENV VITE_READY_PLAYER_ME_URL=$VITE_READY_PLAYER_ME_URL
8586
ENV VITE_DISABLE_LOG=$VITE_DISABLE_LOG
8687
ENV VITE_AVATURN_URL=$VITE_AVATURN_URL
8788
ENV VITE_AVATURN_API=$VITE_AVATURN_API
89+
ENV VITE_FEATHERS_STORE_KEY=$VITE_FEATHERS_STORE_KEY
8890

8991
ARG CACHE_DATE
9092
RUN npx cross-env ts-node --swc scripts/check-db-exists.ts

β€Žpackages/client-core/src/API.tsβ€Ž

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ export class API {
6161
})
6262
)
6363

64-
primus.on('reconnected', () => API.instance.client.reAuthenticate(true))
65-
66-
API.instance = new API()
67-
API.instance.client = feathersClient as any
64+
primus.on('reconnected', () => feathersClient.reAuthenticate(true))
6865

6966
Engine.instance.api = feathersClient
7067
}

β€Žpackages/client-core/src/social/services/LocationService.tsβ€Ž

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import { Engine } from '@etherealengine/ecs/src/Engine'
3030
import { defineState, getMutableState } from '@etherealengine/hyperflux'
3131

3232
import { locationBanPath, SceneID, UserID } from '@etherealengine/common/src/schema.type.module'
33-
import { API } from '../../API'
3433
import { NotificationService } from '../../common/services/NotificationService'
3534

3635
export const LocationSeed: LocationType = {
@@ -129,15 +128,15 @@ export const LocationService = {
129128
getLocation: async (locationId: LocationID) => {
130129
try {
131130
LocationState.fetchingCurrentSocialLocation()
132-
const location = await API.instance.client.service(locationPath).get(locationId)
131+
const location = await Engine.instance.api.service(locationPath).get(locationId)
133132
LocationState.socialLocationRetrieved(location)
134133
} catch (err) {
135134
NotificationService.dispatchNotify(err.message, { variant: 'error' })
136135
}
137136
},
138137
getLocationByName: async (locationName: string) => {
139138
LocationState.fetchingCurrentSocialLocation()
140-
const locationResult = (await API.instance.client.service(locationPath).find({
139+
const locationResult = (await Engine.instance.api.service(locationPath).find({
141140
query: {
142141
slugifiedName: locationName
143142
}
@@ -155,7 +154,7 @@ export const LocationService = {
155154
}
156155
},
157156
getLobby: async () => {
158-
const lobbyResult = (await API.instance.client.service(locationPath).find({
157+
const lobbyResult = (await Engine.instance.api.service(locationPath).find({
159158
query: {
160159
isLobby: true,
161160
$limit: 1
@@ -170,7 +169,7 @@ export const LocationService = {
170169
},
171170
banUserFromLocation: async (userId: UserID, locationId: LocationID) => {
172171
try {
173-
await API.instance.client.service(locationBanPath).create({
172+
await Engine.instance.api.service(locationBanPath).create({
174173
userId: userId,
175174
locationId: locationId
176175
})

β€Žpackages/client-core/src/user/components/UserMenu/menus/LocationMenu.tsxβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import TextField from '@etherealengine/ui/src/primitives/mui/TextField'
4141
import Typography from '@etherealengine/ui/src/primitives/mui/Typography'
4242

4343
import { SceneID } from '@etherealengine/common/src/schema.type.module'
44-
import { API } from '../../../../API'
44+
import { Engine } from '@etherealengine/ecs/src/Engine'
4545
import { LocationSeed } from '../../../../social/services/LocationService'
4646
import styles from '../index.module.scss'
4747

@@ -69,7 +69,7 @@ const LocationMenu = (props: Props) => {
6969
}, [])
7070

7171
const fetchLocations = (page: number, rows: number, search?: string) => {
72-
API.instance.client
72+
Engine.instance.api
7373
.service(locationPath)
7474
.find({
7575
query: {

0 commit comments

Comments
Β (0)