This repository has been archived by the owner on May 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds channel filter to sold domains
- Loading branch information
Showing
4 changed files
with
67 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,33 @@ | ||
import { ServiceAddons, Params } from '@feathersjs/feathers'; | ||
import { AuthenticationService, JWTStrategy, AuthenticationResult, AuthenticationBaseStrategy } from '@feathersjs/authentication'; | ||
import { Application } from '../definitions'; | ||
import { ServiceAddons, Params } from '@feathersjs/feathers' | ||
import { AuthenticationService, AuthenticationBaseStrategy, AuthenticationRequest } from '@feathersjs/authentication' | ||
import { Application } from '../definitions' | ||
|
||
declare module '../definitions' { | ||
interface ServiceTypes { | ||
'authentication': AuthenticationService & ServiceAddons<any>; | ||
'authentication': AuthenticationService & ServiceAddons<any> | ||
} | ||
} | ||
|
||
class MyJWT extends JWTStrategy { | ||
async authenticate(authentication: AuthenticationResult, params: Params) { | ||
console.log('MyJWT -> authenticate------------------------------') | ||
console.log(authentication) | ||
console.log('------------------------------') | ||
console.log(params) | ||
console.log('------------------------------') | ||
return super.authenticate(authentication, params) | ||
} | ||
} | ||
class AnonymousStrategy extends AuthenticationBaseStrategy { | ||
async authenticate(authentication, params) { | ||
authenticate(authentication: AuthenticationRequest, params: Params) { | ||
const channels: [] = authentication.channels | ||
console.log('AnonymousStrategy -> authenticate------------------------------') | ||
console.log(authentication) | ||
console.log('------------------------------') | ||
params.connection.ownerAddress = authentication.ownerAddress | ||
channels.forEach(channel => { | ||
this.app?.channel(channel).join(params.connection) | ||
}); | ||
console.log('this.app.channels:', this.app.channels) | ||
console.log('------------------------------') | ||
return { | ||
anonymous: true | ||
} | ||
} | ||
} | ||
|
||
class MyAuthService extends AuthenticationService { | ||
async getPayload(authResult, params) { | ||
// Call original `getPayload` first | ||
const payload = await super.getPayload(authResult, params); | ||
const { user } = authResult; | ||
}) | ||
|
||
if (user && user.permissions) { | ||
payload.permissions = user.permissions; | ||
} | ||
|
||
return payload; | ||
return Promise.resolve({ anonymous: true }) | ||
} | ||
} | ||
|
||
export default function (app: Application) { | ||
const authentication = new MyAuthService(app as any) //FIXME: remove `as any` | ||
const authentication = new AuthenticationService(app as any) | ||
|
||
app.set('authentication', { | ||
"secret": "8a58b86565c23c9ea90", | ||
"entity": null, | ||
"authStrategies": ["anonymous"], | ||
secret: '8a58b86565c23c9ea90', | ||
entity: null, | ||
authStrategies: ['anonymous'] | ||
}) | ||
|
||
authentication.register('anonymous', new AnonymousStrategy()); | ||
// authentication.register('jwt', new MyJWT()); | ||
|
||
app.use('/authentication', authentication); | ||
} | ||
authentication.register('anonymous', new AnonymousStrategy()) | ||
app.use('/authentication', authentication) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters