Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Single Sign On #1963

Merged
merged 17 commits into from
Aug 8, 2023
3 changes: 2 additions & 1 deletion webapp/config-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = override(
path.resolve(__dirname, 'src'),
path.resolve(__dirname, 'node_modules/react-virtualized-auto-sizer'),
path.resolve(__dirname, 'node_modules/decentraland-connect/node_modules/@walletconnect'),
path.resolve(__dirname, 'node_modules/@walletconnect')
path.resolve(__dirname, 'node_modules/@walletconnect'),
path.resolve(__dirname, 'node_modules/@dcl/single-sign-on-client'),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Package has some unsupported operators by the bundler version used here like ??. So it has to be added in the overrides.

])
)
124 changes: 31 additions & 93 deletions webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"dependencies": {
"@dcl/crypto": "^3.0.0",
"@dcl/schemas": "^8.1.0",
"@dcl/single-sign-on-client": "^0.0.11",
"@dcl/ui-env": "^1.2.0",
"@ethersproject/providers": "^5.6.2",
"@well-known-components/fetch-component": "^2.0.1",
Expand Down Expand Up @@ -113,5 +114,10 @@
"last 1 safari version"
]
},
"homepage": ""
"homepage": "",
"jest": {
"moduleNameMapper": {
"@dcl/single-sign-on-client": "identity-obj-proxy"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the module is an ESM and not CommonJs, jest doesn't like it. Doing this will replace it in tests with a mockable stub.

}
}
}
3 changes: 2 additions & 1 deletion webapp/src/config/env/dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
"MIN_SALE_VALUE_IN_WEI": "1000000000000000000",
"EXPLORER_URL": "https://play.decentraland.zone",
"MARKETPLACE_URL": "https://market.decentraland.zone",
"PROFILE_URL": "https://profile.decentraland.zone"
"PROFILE_URL": "https://profile.decentraland.zone",
"SSO_URL": "https://id.decentraland.zone"
}
3 changes: 2 additions & 1 deletion webapp/src/config/env/prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
"MIN_SALE_VALUE_IN_WEI": "1000000000000000000",
"EXPLORER_URL": "https://play.decentraland.org",
"MARKETPLACE_URL": "https://market.decentraland.org",
"PROFILE_URL": "https://profile.decentraland.org"
"PROFILE_URL": "https://profile.decentraland.org",
"SSO_URL": "https://id.decentraland.org"
}
3 changes: 2 additions & 1 deletion webapp/src/config/env/stg.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
"MIN_SALE_VALUE_IN_WEI": "1000000000000000000",
"EXPLORER_URL": "https://play.decentraland.org",
"MARKETPLACE_URL": "https://market.decentraland.today",
"PROFILE_URL": "https://profile.decentraland.today"
"PROFILE_URL": "https://profile.decentraland.today",
"SSO_URL": "https://id.decentraland.today"
}
9 changes: 8 additions & 1 deletion webapp/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'
import { ConnectedRouter } from 'connected-react-router'
import { ScrollToTop } from './components/ScrollToTop'
import * as SingleSignOn from '@dcl/single-sign-on-client'
import WalletProvider from 'decentraland-dapps/dist/providers/WalletProvider'
import ToastProvider from 'decentraland-dapps/dist/providers/ToastProvider'
import TranslationProvider from 'decentraland-dapps/dist/providers/TranslationProvider'
Expand All @@ -11,14 +11,21 @@ import './setup'
import './modules/analytics/track'
import './modules/analytics/rollbar'

import { ScrollToTop } from './components/ScrollToTop'
import * as locales from './modules/translation/locales'
import { initStore, history } from './modules/store'
import { Routes } from './components/Routes'
import * as modals from './components/Modals'
import { config } from './config'

import './themes'
import './index.css'

// Initializes the SSO client.
// This will create a new iframe and append it to the body.
// It is ideal to do this as soon as possible to avoid any availability issues.
SingleSignOn.init(config.get('SSO_URL'))

async function main() {
const component = (
<Provider store={initStore()}>
Expand Down
73 changes: 60 additions & 13 deletions webapp/src/modules/identity/sagas.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
import { expectSaga } from 'redux-saga-test-plan'
import { put } from 'redux-saga-test-plan/matchers'
import { select } from 'redux-saga/effects'
import { call } from 'redux-saga/effects'
import { Wallet } from 'decentraland-dapps/dist/modules/wallet/types'
import { connectWalletSuccess } from 'decentraland-dapps/dist/modules/wallet/actions'
import { getCurrentIdentity } from './selectors'
import { identitySaga } from './sagas'
import { generateIdentityRequest } from './actions'
import {
connectWalletSuccess,
disconnectWallet
} from 'decentraland-dapps/dist/modules/wallet/actions'
import { getIdentity, clearIdentity } from '@dcl/single-sign-on-client'
import { identitySaga, setAuxAddress } from './sagas'
import { generateIdentityRequest, generateIdentitySuccess } from './actions'

jest.mock('@dcl/single-sign-on-client', () => {
return {
getIdentity: jest.fn(),
clearIdentity: jest.fn()
}
})

beforeEach(() => {
jest.resetAllMocks()

setAuxAddress(null)
})

describe('when handling the wallet connection success', () => {
let wallet: Wallet

beforeEach(() => {
wallet = {
address: '0x0'
Expand All @@ -18,23 +34,54 @@ describe('when handling the wallet connection success', () => {
describe("and there's no identity", () => {
it('should put an action to generate the identity', () => {
return expectSaga(identitySaga)
.provide([
[select(getCurrentIdentity), null],
[put(generateIdentityRequest(wallet.address)), undefined]
])
.provide([[call(getIdentity, wallet.address), null]])
.put(generateIdentityRequest(wallet.address))
.dispatch(connectWalletSuccess(wallet))
.run({ silenceTimeout: true })
})
})

describe("and there's an identity", () => {
it('should not put an action to generate the identity', () => {
it('should put an action to store the identity', () => {
const identity = {} as any

return expectSaga(identitySaga)
.provide([[select(getCurrentIdentity), {}]])
.not.put(generateIdentityRequest(wallet.address))
.provide([[call(getIdentity, wallet.address), identity]])
.put(generateIdentitySuccess(wallet.address, identity))
.dispatch(connectWalletSuccess(wallet))
.run({ silenceTimeout: true })
})
})
})

describe('when handling the disconnect', () => {
describe('when the auxiliary address is set', () => {
const address = '0xSomeAddress'

beforeEach(() => {
setAuxAddress(address)
})

it('should call the sso client to clear the identity', async () => {
await expectSaga(identitySaga)
.dispatch(disconnectWallet())
.run({ silenceTimeout: true })

expect(clearIdentity).toHaveBeenCalledWith(address)
})
})

describe('when the auxiliary address is not set', () => {
beforeEach(() => {
setAuxAddress(null)
})

it('should not call the sso client to clear the identity', async () => {
await expectSaga(identitySaga)
.dispatch(disconnectWallet())
.run({ silenceTimeout: true })

expect(clearIdentity).not.toHaveBeenCalled()
})
})
})
Loading
Loading