Skip to content
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
5 changes: 4 additions & 1 deletion apps/event-system/services/api/routes/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export const publicRoute = () => ({

'v1.connection-testing.public.testConnectionModel',
'v1.stripe-webhook.handleWebhook',

'v3.users.mockOauth',
],

aliases: {
Expand All @@ -52,7 +54,8 @@ export const publicRoute = () => ({

'POST v1/embed-tokens/get': 'v1.embed-tokens.public.get',
'POST v1/embed-tokens/update': 'v1.embed-tokens.public.update',
'POST v1/stripe-webhook': 'v1.stripe-webhook.handleWebhook'
'POST v1/stripe-webhook': 'v1.stripe-webhook.handleWebhook',
'POST v3/users/mock-oauth': 'v3.users.mockOauth',

},

Expand Down
115 changes: 115 additions & 0 deletions apps/event-system/services/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,121 @@ module.exports = {
}
},
},
mockOauth: {

params: {
user: {
type: 'object',
props: {
login: { type: 'string' },
id: { type: 'number' },
node_id: { type: 'string' },
avatar_url: { type: 'string' },
gravatar_id: { type: 'string' },
url: { type: 'string' },
type: { type: 'string' },
user_view_type: { type: 'string' },
site_admin: { type: 'boolean' },
name: { type: 'string' },
},
},
emails: {
type: 'array',
items: {
type: 'object',
props: {
email: { type: 'string' },
primary: { type: 'boolean' },
verified: { type: 'boolean' },
visibility: { type: 'string' },
},
},
},
},

async handler (ctx: any) {
try {

const secretKey = ctx?.meta?.request?.headers?.['x-mock-user-secret-key'];
if (secretKey !== process.env.MOCK_USER_SECRET_KEY) {
throw new MoleculerError(
'The secret key is invalid',
401,
'unauthorized',
{}
);
}

const { user, emails } = ctx.params;

const email = emails?.[0]?.email;
const username = user.login;
const [firstName, lastName] = getFirstAndLastNameFromName(user.name);
const avatar = user.avatar_url;
const profileLink = user.url;

let _user;

// Create or update user
try {
_user = await this.createOrUpdateUser({
ctx,
provider: 'mock',
user,
emails,
email,
username,
firstName,
lastName,
avatar,
profileLink,
});
} catch (error) {
console.error(error);
if (error.type === new OAuthAccountAlreadyAssociated().type) {
throw error;
}
throw new AuthGenericError();
}

// Create token
try {
const { _id, email, userKey, firstName, lastName, state, pointers } =
_user;
// use buildableId in client due to old users having user.buildableId == coreId
const buildableId = get(_user, 'client.buildableId');
const containerId = get(_user, 'client.containers[0]._id');

const token = this.createToken({
_id,
email,
username,
userKey,
buildableId,
containerId,
firstName,
lastName,
pointers,
});

return {
token,
state,
};
} catch (error) {
console.error(error);
throw new AuthGenericError();
}


}
catch (error) {
console.error(error);
throw new AuthGenericError();
}
}

},
},

methods: {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

Loading