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

Fix identity-provider type issues & patch @feathersjs/knex #10971

Merged
merged 8 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 @@ -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
21 changes: 21 additions & 0 deletions patches/@feathersjs+knex+5.0.5.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/node_modules/@feathersjs/knex/lib/adapter.js b/node_modules/@feathersjs/knex/lib/adapter.js
index e6851d4..afacfd8 100644
--- a/node_modules/@feathersjs/knex/lib/adapter.js
+++ b/node_modules/@feathersjs/knex/lib/adapter.js
@@ -125,9 +125,14 @@ class KnexAdapter extends adapter_commons_1.AdapterBase {
}
async _find(params = {}) {
const { filters, paginate } = this.filterQuery(params);
- const { name, id } = this.getOptions(params);
+ const { Model, name, id } = this.getOptions(params);
const builder = params.knex ? params.knex.clone() : this.createQuery(params);
- const countBuilder = builder.clone().clearSelect().clearOrder().count(`${name}.${id} as total`);
+ const countBuilder = Model.count(`* as total`)
+ .with(
+ 'subquery',
+ builder.clone().clearOrder()
+ )
+ .from('subquery');
// Handle $limit
if (filters.$limit) {
builder.limit(filters.$limit);
Loading