1+ /* eslint-disable camelcase */
12import * as dotenv from 'dotenv' ;
23import * as jwt from 'jsonwebtoken' ;
34
5+ import { CommonConstants , uuidRegex } from '@credebl/common/common.constant' ;
46import { ExtractJwt , Strategy } from 'passport-jwt' ;
57import { Injectable , Logger , NotFoundException , UnauthorizedException } from '@nestjs/common' ;
68
79import { AuthzService } from './authz.service' ;
8- import { CommonConstants , uuidRegex } from '@credebl/common/common.constant' ;
9- import { EcosystemService } from '../ecosystem/ecosystem.service' ;
1010import { IOrganization } from '@credebl/common/interfaces/organization.interface' ;
1111import { JwtPayload } from './jwt-payload.interface' ;
1212import { OrganizationService } from '../organization/organization.service' ;
@@ -24,8 +24,7 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
2424 constructor (
2525 private readonly usersService : UserService ,
2626 private readonly organizationService : OrganizationService ,
27- private readonly authzService : AuthzService ,
28- private readonly ecosystemService : EcosystemService
27+ private readonly authzService : AuthzService
2928 ) {
3029 super ( {
3130 jwtFromRequest : ExtractJwt . fromAuthHeaderAsBearerToken ( ) ,
@@ -74,20 +73,6 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
7473 if ( payload ?. email ) {
7574 userInfo = await this . usersService . getUserByUserIdInKeycloak ( payload ?. email ) ;
7675 }
77- let ecosystemRole = null ;
78- if ( userInfo ?. id ) {
79- try {
80- const user = await this . ecosystemService . getUserByKeycloakId ( userInfo . id ) ;
81- if ( user ?. id ) {
82- const ecosystem = await this . ecosystemService . getEcosystemDetailsByUserId ( user . id ) ;
83- if ( ecosystem ?. id ) {
84- ecosystemRole = await this . ecosystemService . getEcosystemOrgDetailsByUserId ( user . id , ecosystem . id ) ;
85- }
86- }
87- } catch ( error ) {
88- this . logger . warn ( 'Failed to fetch ecosystem roles' , JSON . stringify ( error ) ) ;
89- }
90- }
9176
9277 if ( payload . hasOwnProperty ( 'client_id' ) && uuidRegex . test ( payload [ 'client_id' ] ) ) {
9378 const orgDetails : IOrganization = await this . organizationService . findOrganizationOwner ( payload [ 'client_id' ] ) ;
@@ -122,11 +107,8 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
122107 userDetails [ 'userRole' ] = userInfo ?. [ 'attributes' ] ?. userRole ;
123108 }
124109
125- if ( Array . isArray ( ecosystemRole ) && 0 < ecosystemRole . length ) {
126- const ecosystemRoleList = [
127- ...new Set ( ecosystemRole . map ( ( record : { ecosystemRole : { name : string } } ) => record . ecosystemRole . name ) )
128- ] ;
129- userDetails . ecosystemRoles = ecosystemRoleList ;
110+ if ( userDetails && payload ?. ecosystem_access ) {
111+ userDetails . ecosystem_access = payload . ecosystem_access ;
130112 }
131113
132114 return {
0 commit comments