Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
194 lines
5.1 KiB
TypeScript
194 lines
5.1 KiB
TypeScript
import type { IUser } from '@rocket.chat/core-typings';
|
|
import { License } from '@rocket.chat/license';
|
|
import { serverFetch as fetch } from '@rocket.chat/server-fetch';
|
|
import Gravatar from 'gravatar';
|
|
import { check } from 'meteor/check';
|
|
import { ServiceConfiguration } from 'meteor/service-configuration';
|
|
|
|
import { warnGravatarDeprecation } from './gravatarDeprecation';
|
|
import { settings } from '../../settings';
|
|
|
|
const avatarProviders = {
|
|
facebook(user: IUser) {
|
|
if (user.services?.facebook?.id && settings.get('Accounts_OAuth_Facebook')) {
|
|
return {
|
|
service: 'facebook',
|
|
url: `https://graph.facebook.com/${user.services.facebook.id}/picture?type=large`,
|
|
};
|
|
}
|
|
},
|
|
|
|
google(user: IUser) {
|
|
if (
|
|
user.services?.google?.picture &&
|
|
user.services.google.picture !== 'https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg' &&
|
|
settings.get('Accounts_OAuth_Google')
|
|
) {
|
|
return {
|
|
service: 'google',
|
|
url: user.services.google.picture,
|
|
};
|
|
}
|
|
},
|
|
|
|
github(user: IUser) {
|
|
if (user.services?.github?.username && settings.get('Accounts_OAuth_Github')) {
|
|
return {
|
|
service: 'github',
|
|
url: `https://avatars.githubusercontent.com/${user.services.github.username}?s=200`,
|
|
};
|
|
}
|
|
},
|
|
|
|
linkedin(user: IUser) {
|
|
if (
|
|
user.services?.linkedin?.profilePicture?.identifiersUrl &&
|
|
user.services.linkedin.profilePicture.identifiersUrl.length > 0 &&
|
|
settings.get('Accounts_OAuth_Linkedin')
|
|
) {
|
|
const total = user.services.linkedin.profilePicture.identifiersUrl.length;
|
|
return {
|
|
service: 'linkedin',
|
|
url: user.services.linkedin.profilePicture.identifiersUrl[total - 1],
|
|
};
|
|
}
|
|
},
|
|
|
|
twitter(user: IUser) {
|
|
if (user.services?.twitter?.profile_image_url_https && settings.get('Accounts_OAuth_Twitter')) {
|
|
return {
|
|
service: 'twitter',
|
|
url: user.services.twitter.profile_image_url_https.replace(/_normal|_bigger/, ''),
|
|
};
|
|
}
|
|
},
|
|
|
|
gitlab(user: IUser) {
|
|
if (user.services?.gitlab?.avatar_url && settings.get('Accounts_OAuth_Gitlab')) {
|
|
return {
|
|
service: 'gitlab',
|
|
url: user.services.gitlab.avatar_url,
|
|
};
|
|
}
|
|
},
|
|
|
|
async customOAuth(user: IUser) {
|
|
const avatars: { service: string; url: string }[] = [];
|
|
if (!user.services) {
|
|
return avatars;
|
|
}
|
|
|
|
await Promise.all(
|
|
Object.keys(user.services).map(async (service) => {
|
|
if (!user.services) {
|
|
return;
|
|
}
|
|
|
|
if (user.services[service as keyof typeof user.services]._OAuthCustom) {
|
|
const services = await ServiceConfiguration.configurations.find({ service }, { fields: { secret: 0 } }).fetchAsync();
|
|
|
|
if (services.length > 0) {
|
|
if (user.services[service as keyof typeof user.services].avatarUrl) {
|
|
avatars.push({
|
|
service,
|
|
url: user.services[service as keyof typeof user.services].avatarUrl,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}),
|
|
);
|
|
|
|
return avatars;
|
|
},
|
|
|
|
emails(user: IUser) {
|
|
const avatars: { service: string; url: string }[] = [];
|
|
|
|
// Offline (air-gapped) licenses suppress Gravatar lookups: every suggested
|
|
// URL is fetched server-side below, and gravatar.com is not admin-configured
|
|
// infrastructure (unlike OAuth provider avatars, which keep working).
|
|
if (License.hasOfflineLicense()) {
|
|
return avatars;
|
|
}
|
|
|
|
if (user.emails && user.emails.length > 0) {
|
|
warnGravatarDeprecation();
|
|
|
|
for (const email of user.emails) {
|
|
if (email.verified === true) {
|
|
avatars.push({
|
|
service: 'gravatar',
|
|
url: Gravatar.url(email.address, {
|
|
default: '404',
|
|
size: '200',
|
|
protocol: 'https',
|
|
}),
|
|
});
|
|
}
|
|
|
|
if (email.verified !== true) {
|
|
avatars.push({
|
|
service: 'gravatar',
|
|
url: Gravatar.url(email.address, {
|
|
default: '404',
|
|
size: '200',
|
|
protocol: 'https',
|
|
}),
|
|
});
|
|
}
|
|
}
|
|
}
|
|
return avatars;
|
|
},
|
|
};
|
|
|
|
/**
|
|
* @return {Object}
|
|
*/
|
|
export async function getAvatarSuggestionForUser(
|
|
user: IUser,
|
|
): Promise<Record<string, { blob: string; contentType: string; service: string; url: string }>> {
|
|
check(user, Object);
|
|
|
|
const avatars = [];
|
|
|
|
for (const avatarProvider of Object.values(avatarProviders)) {
|
|
const avatar = await avatarProvider(user);
|
|
if (avatar) {
|
|
if (Array.isArray(avatar)) {
|
|
avatars.push(...avatar);
|
|
} else {
|
|
avatars.push(avatar);
|
|
}
|
|
}
|
|
}
|
|
|
|
const validAvatars: Record<string, { blob: string; contentType: string; service: string; url: string }> = {};
|
|
for (const avatar of avatars) {
|
|
try {
|
|
const response = await fetch(avatar.url, {
|
|
ignoreSsrfValidation: false,
|
|
allowList: settings.get<string>('SSRF_Allowlist'),
|
|
});
|
|
const newAvatar: { service: string; url: string; blob: string; contentType: string } = {
|
|
service: avatar.service,
|
|
url: avatar.url,
|
|
blob: '',
|
|
contentType: '',
|
|
};
|
|
|
|
if (response.status === 200) {
|
|
let blob = `data:${response.headers.get('content-type')};base64,`;
|
|
blob += Buffer.from(await response.arrayBuffer()).toString('base64');
|
|
newAvatar.blob = blob;
|
|
newAvatar.contentType = response.headers.get('content-type') as string;
|
|
validAvatars[avatar.service] = newAvatar;
|
|
}
|
|
} catch (error) {
|
|
// error;
|
|
}
|
|
}
|
|
return validAvatars;
|
|
}
|