X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fauth%2Foauth-model.ts;h=d9cf328272cf42792e7d3cb9c2102bf5b98100f5;hb=927fa4b11f692174d6296aa096d7a74bacdeea8b;hp=81b6529d8462e23157167d9cc3665d4a6247d9e0;hpb=400ed2ab4155689d1695cfbce9358f9ca3a5da60;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/auth/oauth-model.ts b/server/lib/auth/oauth-model.ts index 81b6529d8..d9cf32827 100644 --- a/server/lib/auth/oauth-model.ts +++ b/server/lib/auth/oauth-model.ts @@ -1,18 +1,18 @@ import express from 'express' -import { AccessDeniedError } from 'oauth2-server' +import { AccessDeniedError } from '@node-oauth/oauth2-server' import { PluginManager } from '@server/lib/plugins/plugin-manager' import { ActorModel } from '@server/models/actor/actor' import { MOAuthClient } from '@server/types/models' import { MOAuthTokenUser } from '@server/types/models/oauth/oauth-token' import { MUser } from '@server/types/models/user/user' -import { UserAdminFlag } from '@shared/models/users/user-flag.model' +import { pick } from '@shared/core-utils' import { UserRole } from '@shared/models/users/user-role' import { logger } from '../../helpers/logger' import { CONFIG } from '../../initializers/config' -import { UserModel } from '../../models/user/user' import { OAuthClientModel } from '../../models/oauth/oauth-client' import { OAuthTokenModel } from '../../models/oauth/oauth-token' -import { createUserAccountAndChannelAndPlaylist } from '../user' +import { UserModel } from '../../models/user/user' +import { buildUser, createUserAccountAndChannelAndPlaylist } from '../user' import { TokensCache } from './tokens-cache' type TokenInfo = { @@ -116,6 +116,7 @@ async function getUser (usernameOrEmail?: string, password?: string, bypassLogin logger.debug('Getting User (username/email: ' + usernameOrEmail + ', password: ******).') const user = await UserModel.loadByUsernameOrEmail(usernameOrEmail) + // If we don't find the user, or if the user belongs to a plugin if (!user || user.pluginAuth !== null || !password) return null @@ -228,19 +229,13 @@ async function createUserFromExternal (pluginAuth: string, options: { const actor = await ActorModel.loadLocalByName(options.username) if (actor) return null - const userToCreate = new UserModel({ - username: options.username, + const userToCreate = buildUser({ + ...pick(options, [ 'username', 'email', 'role' ]), + + emailVerified: null, password: null, - email: options.email, - nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, - p2pEnabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED, - autoPlayVideo: true, - role: options.role, - videoQuota: CONFIG.USER.VIDEO_QUOTA, - videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY, - adminFlags: UserAdminFlag.NONE, pluginAuth - }) as MUser + }) const { user } = await createUserAccountAndChannelAndPlaylist({ userToCreate,