Skip to content

Commit cf0b3e6

Browse files
authored
fix: Use sso local functions (#6055)
* fix: Use sso local functions * fix: Delete session before emiting logout
1 parent 945a64f commit cf0b3e6

File tree

4 files changed

+6
-33
lines changed

4 files changed

+6
-33
lines changed

browser-interface/packages/config/index.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,6 @@ export const QS_MAX_VISIBLE_PEERS =
8282
export const BUILDER_SERVER_URL =
8383
ensureSingleString(qs.get('BUILDER_SERVER_URL')) ?? 'https://builder-api.decentraland.org/v1'
8484

85-
const SSO_URL = ensureQueryStringUrl(qs.get('SSO_URL')) ?? 'https://id.decentraland.org'
86-
export function getSSOUrl() {
87-
const sso = new URL(SSO_URL)
88-
const ssoHost = sso.hostname.split('.').reverse()
89-
const currentHost = location.hostname.split('.').reverse()
90-
91-
// ensures the same top level domain for the SSO
92-
if (ssoHost[0] === currentHost[0] && ssoHost[1] === currentHost[1]) {
93-
return SSO_URL
94-
}
95-
96-
return null
97-
}
98-
9985
/**
10086
* Get the root URL and ensure not to end with slash
10187
* @returns Root URL with pathname where the index.html is served.

browser-interface/packages/entryPoints/index.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import { ETHEREUM_NETWORK, HAS_INITIAL_POSITION_MARK, getSSOUrl } from 'config/index'
1+
import { ETHEREUM_NETWORK, HAS_INITIAL_POSITION_MARK } from 'config/index'
22
import { WebSocketProvider } from 'eth-connect'
33
import { IDecentralandKernel, IEthereumProvider, KernelOptions, KernelResult, LoginState } from '@dcl/kernel-interface'
4-
import * as SingleSignOn from '@dcl/single-sign-on-client'
54
import { getFromPersistentStorage, setPersistentStorage } from 'lib/browser/persistentStorage'
65
import { gridToWorld } from 'lib/decentraland/parcels/gridToWorld'
76
import { parseParcelPosition } from 'lib/decentraland/parcels/parseParcelPosition'
87
import { resolveBaseUrl } from 'lib/decentraland/url/resolveBaseUrl'
98
import { storeCondition } from 'lib/redux/storeCondition'
10-
import { defaultLogger } from 'lib/logger'
119
import { initShared } from 'shared'
1210
import { sendHomeScene } from 'shared/atlas/actions'
1311
import { homePointKey } from 'shared/atlas/utils'
@@ -33,15 +31,6 @@ import { isWebGLCompatible } from './validations'
3331
declare const globalThis: { DecentralandKernel: IDecentralandKernel }
3432
globalThis.DecentralandKernel = {
3533
async initKernel(options: KernelOptions): Promise<KernelResult> {
36-
try {
37-
let sso = getSSOUrl()
38-
if (sso) {
39-
SingleSignOn.init(sso)
40-
}
41-
} catch (err) {
42-
defaultLogger.error('Error initializing SingleSignOn', err)
43-
}
44-
4534
await setupBaseUrl(options)
4635

4736
ensureValidWebGLCanvasContainer(options)

browser-interface/packages/shared/session/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const deleteSession = async (userId?: string) => {
2626
if (userId) {
2727
await removeFromPersistentStorage(sessionKey(userId))
2828

29-
await SingleSignOn.clearIdentity(userId)
29+
SingleSignOn.localStorageClearIdentity(userId)
3030
}
3131
}
3232

@@ -56,7 +56,7 @@ async function getSessionWithSSOIdentity(sessions: StoredSession[]) {
5656

5757
const session = sessions[0]
5858

59-
const ssoIdentity = await SingleSignOn.getIdentity(session.identity.address)
59+
const ssoIdentity = SingleSignOn.localStorageGetIdentity(session.identity.address)
6060

6161
if (!ssoIdentity || isSessionExpired({ identity: ssoIdentity })) {
6262
return null

browser-interface/packages/shared/session/sagas.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,12 @@ async function createAuthIdentity(requestManager: RequestManager, isGuest: boole
319319

320320
let auth: AuthIdentity
321321

322-
const ssoIdentity = await SingleSignOn.getIdentity(address)
322+
const ssoIdentity = SingleSignOn.localStorageGetIdentity(address)
323323

324324
if (!ssoIdentity || isSessionExpired({ identity: ssoIdentity })) {
325325
auth = await Authenticator.initializeAuthChain(address, ephemeral, ephemeralLifespanMinutes, signer)
326326

327-
await SingleSignOn.storeIdentity(address, auth)
327+
SingleSignOn.localStorageStoreIdentity(address, auth)
328328
} else {
329329
auth = ssoIdentity
330330
}
@@ -337,14 +337,12 @@ function* logout() {
337337
const network: ETHEREUM_NETWORK = yield select(getSelectedNetwork)
338338
if (identity && identity.address && network) {
339339
yield call(() => localProfilesRepo.remove(identity.address, network))
340+
yield call(deleteSession, identity.address)
340341
globalObservable.emit('logout', { address: identity.address, network })
341342
}
342343

343344
yield put(setRoomConnection(undefined))
344345

345-
if (identity?.address) {
346-
yield call(deleteSession, identity.address)
347-
}
348346
window.location.reload()
349347
}
350348

0 commit comments

Comments
 (0)