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

Commit

Permalink
Merge branch 'dev' into IR-3459-unit-test-spatial-renderer-components…
Browse files Browse the repository at this point in the history
…-coverage
  • Loading branch information
heysokam committed Aug 15, 2024
2 parents 8a8d826 + 374551b commit 9ae468f
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { useTranslation } from 'react-i18next'
import { Link, useLocation } from 'react-router-dom'

import Avatar from '@etherealengine/client-core/src/common/components/Avatar'
import Button from '@etherealengine/client-core/src/common/components/Button'
import commonStyles from '@etherealengine/client-core/src/common/components/common.module.scss'
import ConfirmDialog from '@etherealengine/client-core/src/common/components/ConfirmDialog'
import { AppleIcon } from '@etherealengine/client-core/src/common/components/Icons/AppleIcon'
Expand Down Expand Up @@ -322,51 +321,51 @@ const ProfileMenu = ({ hideLogin, onClose, isPopover }: Props): JSX.Element => {
// console.log('VC Request query result:', result)
}

async function handleWalletLoginClick() {
const domain = window.location.origin
const challenge = '99612b24-63d9-11ea-b99f-4f66f3e4f81a' // TODO: generate

console.log('Sending DIDAuth query...')

const didAuthQuery: any = {
web: {
VerifiablePresentation: {
query: [
{
type: 'DIDAuth' // request the controller's DID
},
{
type: 'QueryByExample',
credentialQuery: [
{
example: {
'@context': ['https://www.w3.org/2018/credentials/v1', 'https://w3id.org/xr/v1'],
// contains username and avatar icon
type: 'LoginDisplayCredential'
}
},
{
example: {
'@context': ['https://www.w3.org/2018/credentials/v1', 'https://w3id.org/xr/v1'],
// various Ethereal Engine user preferences
type: 'UserPreferencesCredential'
}
}
]
}
],
challenge,
domain // e.g.: requestingparty.example.com
}
}
}
// async function handleWalletLoginClick() {
// const domain = window.location.origin
// const challenge = '99612b24-63d9-11ea-b99f-4f66f3e4f81a' // TODO: generate

// console.log('Sending DIDAuth query...')

// const didAuthQuery: any = {
// web: {
// VerifiablePresentation: {
// query: [
// {
// type: 'DIDAuth' // request the controller's DID
// },
// {
// type: 'QueryByExample',
// credentialQuery: [
// {
// example: {
// '@context': ['https://www.w3.org/2018/credentials/v1', 'https://w3id.org/xr/v1'],
// // contains username and avatar icon
// type: 'LoginDisplayCredential'
// }
// },
// {
// example: {
// '@context': ['https://www.w3.org/2018/credentials/v1', 'https://w3id.org/xr/v1'],
// // various Ethereal Engine user preferences
// type: 'UserPreferencesCredential'
// }
// }
// ]
// }
// ],
// challenge,
// domain // e.g.: requestingparty.example.com
// }
// }
// }

// Use Credential Handler API to authenticate and receive basic login display credentials
const vprResult: any = await navigator.credentials.get(didAuthQuery)
console.log(vprResult)
// // Use Credential Handler API to authenticate and receive basic login display credentials
// const vprResult: any = await navigator.credentials.get(didAuthQuery)
// console.log(vprResult)

AuthService.loginUserByXRWallet(vprResult)
}
// AuthService.loginUserByXRWallet(vprResult)
// }

const refreshApiKey = () => {
AuthService.updateApiKey()
Expand Down Expand Up @@ -752,7 +751,7 @@ const ProfileMenu = ({ hideLogin, onClose, isPopover }: Props): JSX.Element => {
</>
)}

{isGuest && enableWalletLogin && (
{/* {isGuest && enableWalletLogin && (
<>
<Text align="center" variant="body2" mb={1} mt={2}>
{t('user:usermenu.profile.or')}
Expand All @@ -776,7 +775,7 @@ const ProfileMenu = ({ hideLogin, onClose, isPopover }: Props): JSX.Element => {
</Box>
)}
</>
)}
)} */}

{enableSocial && (
<>
Expand Down
108 changes: 54 additions & 54 deletions packages/client-core/src/user/services/AuthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,41 +317,41 @@ export const AuthService = {
*
* @param vprResult {object} - VPR Query result from a user's wallet.
*/
async loginUserByXRWallet(vprResult: any) {
const authState = getMutableState(AuthState)
try {
authState.merge({ isProcessing: true, error: '' })

const credentials: any = parseUserWalletCredentials(vprResult)
console.log(credentials)

const walletUser = resolveWalletUser(credentials)
const authUser = {
accessToken: '',
authentication: { strategy: 'did-auth' },
identityProvider: {
id: '',
token: '',
type: 'didWallet',
userId: walletUser.id,
createdAt: '',
updatedAt: ''
}
}

// TODO: This is temp until we move completely to XR wallet #6453
const oldId = authState.user.id.value
walletUser.id = oldId

// loadXRAvatarForUpdatedUser(walletUser)
authState.merge({ isLoggedIn: true, user: walletUser, authUser })
} catch (err) {
authState.merge({ error: i18n.t('common:error.login-error') })
NotificationService.dispatchNotify(err.message, { variant: 'error' })
} finally {
authState.merge({ isProcessing: false, error: '' })
}
},
// async loginUserByXRWallet(vprResult: any) {
// const authState = getMutableState(AuthState)
// try {
// authState.merge({ isProcessing: true, error: '' })

// const credentials: any = parseUserWalletCredentials(vprResult)
// console.log(credentials)

// const walletUser = resolveWalletUser(credentials)
// const authUser = {
// accessToken: '',
// authentication: { strategy: 'did-auth' },
// identityProvider: {
// id: '',
// token: '',
// type: 'didWallet',
// userId: walletUser.id,
// createdAt: '',
// updatedAt: ''
// }
// }

// // TODO: This is temp until we move completely to XR wallet #6453
// const oldId = authState.user.id.value
// walletUser.id = oldId

// // loadXRAvatarForUpdatedUser(walletUser)
// authState.merge({ isLoggedIn: true, user: walletUser, authUser })
// } catch (err) {
// authState.merge({ error: i18n.t('common:error.login-error') })
// NotificationService.dispatchNotify(err.message, { variant: 'error' })
// } finally {
// authState.merge({ isProcessing: false, error: '' })
// }
// },

/**
* Logs in the current user based on an OAuth response.
Expand Down Expand Up @@ -725,25 +725,25 @@ export const AuthService = {
/**
* @param vprResult {any} See `loginUserByXRWallet()`'s docstring.
*/
function parseUserWalletCredentials(vprResult: any) {
console.log('PARSING:', vprResult)

const {
data: { presentation: vp }
} = vprResult
const credentials = Array.isArray(vp.verifiableCredential) ? vp.verifiableCredential : [vp.verifiableCredential]

const { displayName, displayIcon } = parseLoginDisplayCredential(credentials)

return {
user: {
id: vp.holder,
displayName,
icon: displayIcon
// session // this will contain the access token and helper methods
}
}
}
// function parseUserWalletCredentials(vprResult: any) {
// console.log('PARSING:', vprResult)

// const {
// data: { presentation: vp }
// } = vprResult
// const credentials = Array.isArray(vp.verifiableCredential) ? vp.verifiableCredential : [vp.verifiableCredential]

// const { displayName, displayIcon } = parseLoginDisplayCredential(credentials)

// return {
// user: {
// id: vp.holder,
// displayName,
// icon: displayIcon
// // session // this will contain the access token and helper methods
// }
// }
// }

/**
* Parses the user's preferred display name (username) and avatar icon from the
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/interfaces/AuthUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const IdentityProviderSeed: IdentityProviderType = {
accountIdentifier: '',
oauthToken: '',
oauthRefreshToken: '',
type: '',
type: 'guest',
userId: '' as UserID,
createdAt: '',
updatedAt: ''
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/schemas/social/invite.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export const inviteSchema = Type.Object(
format: 'uuid'
}),
token: Type.Optional(Type.String()),

// @ts-ignore
identityProviderType: Type.Optional(StringEnum(identityProviderTypes)),
passcode: Type.Optional(Type.String()),
targetObjectId: Type.Optional(Type.String()),
Expand Down
7 changes: 5 additions & 2 deletions packages/common/src/schemas/user/generate-token.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ Ethereal Engine. All Rights Reserved.

// For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html
import type { Static } from '@feathersjs/typebox'
import { getValidator, querySyntax, Type } from '@feathersjs/typebox'
import { getValidator, querySyntax, StringEnum, Type } from '@feathersjs/typebox'

import { dataValidator, queryValidator } from '../validators'
import { identityProviderTypes } from './identity-provider.schema'

export const generateTokenPath = 'generate-token'

Expand All @@ -37,7 +38,9 @@ export const generateTokenMethods = ['create'] as const
export const generateTokenSchema = Type.Object(
{
token: Type.String(),
type: Type.String()

// @ts-ignore
type: Type.Optional(StringEnum(identityProviderTypes))
},
{ $id: 'GenerateToken', additionalProperties: false }
)
Expand Down
7 changes: 5 additions & 2 deletions packages/common/src/schemas/user/identity-provider.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ export const identityProviderTypes = [
'facebook',
'twitter',
'linkedin',
'auth0'
]
'auth0',
'guest'
] as const

// Main data model schema
export const identityProviderSchema = Type.Object(
Expand All @@ -61,6 +62,8 @@ export const identityProviderSchema = Type.Object(
accountIdentifier: Type.Optional(Type.String()),
oauthToken: Type.Optional(Type.String()),
oauthRefreshToken: Type.Optional(Type.String()),

// @ts-ignore
type: StringEnum(identityProviderTypes),
userId: TypedString<UserID>({
format: 'uuid'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default {
before: {
all: [
iff(isProvider('external'), verifyScope('admin', 'admin')),
() => schemaHooks.validateQuery(analyticsQueryValidator),
schemaHooks.validateQuery(analyticsQueryValidator),
schemaHooks.resolveQuery(analyticsQueryResolver)
],
find: [
Expand All @@ -126,9 +126,9 @@ export default {
discardQuery('action')
],
get: [],
create: [() => schemaHooks.validateData(analyticsDataValidator), schemaHooks.resolveData(analyticsDataResolver)],
create: [schemaHooks.validateData(analyticsDataValidator), schemaHooks.resolveData(analyticsDataResolver)],
update: [],
patch: [() => schemaHooks.validateData(analyticsPatchValidator), schemaHooks.resolveData(analyticsPatchResolver)],
patch: [schemaHooks.validateData(analyticsPatchValidator), schemaHooks.resolveData(analyticsPatchResolver)],
remove: []
},

Expand Down
18 changes: 17 additions & 1 deletion packages/server-core/src/projects/project/project-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,19 @@ const staticResourceClasses = [
AssetType.Prefab
]

const ignoreFiles = ['.ds_store']

/**
* Checks whether a file is to be ignored in resources.json and static-resources
* @param key
*/
export const isIgnoredFile = (key: string) => {
for (const ignoreFile of ignoreFiles) {
if (key.includes(ignoreFile)) return true
}
return false
}

/**
* Updates the local storage provider with the project's current files
* @param app Application object
Expand Down Expand Up @@ -1757,7 +1770,10 @@ export const uploadLocalProjectToProvider = async (
},
{ isDirectory: false }
)
if (!filePathRelative.startsWith(`assets/`) && !filePathRelative.startsWith(`public/`)) {
if (
(!filePathRelative.startsWith(`assets/`) && !filePathRelative.startsWith(`public/`)) ||
isIgnoredFile(filePathRelative)
) {
existingKeySet.delete(key)
continue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ async function addIdentityProviderType(context: HookContext<IdentityProviderServ
})

if (adminScopes.total === 0 && (isDev || (context.actualData as IdentityProviderData).type !== 'guest')) {
;(context.actualData as IdentityProviderData).type = 'admin'
context.isAdmin = true
}
}

Expand Down Expand Up @@ -245,7 +245,7 @@ async function createNewUser(context: HookContext<IdentityProviderService>) {
/* (AFTER) CREATE HOOKS */

async function addScopes(context: HookContext<IdentityProviderService>) {
if (isDev && (context.actualData as IdentityProviderType).type === 'admin') {
if (isDev && context.isAdmin === true) {
// in dev mode, add all scopes to the first user made an admin
const scopeTypes = await context.app.service(scopeTypePath).find({
paginate: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ describe('identity-provider.service', () => {
assert.equal(createdIdentityProvider.type, type)
assert.equal(createdIdentityProvider.token, token)
assert.ok(createdIdentityProvider.accessToken)
assert.equal(createdIdentityProvider.userId, userId)
})

it('should create an identity provider for email', async () => {
Expand Down
Loading

0 comments on commit 9ae468f

Please sign in to comment.