aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/auth/oauth-model.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/auth/oauth-model.ts')
-rw-r--r--server/lib/auth/oauth-model.ts22
1 files changed, 6 insertions, 16 deletions
diff --git a/server/lib/auth/oauth-model.ts b/server/lib/auth/oauth-model.ts
index 322b69e3a..603cc0f5f 100644
--- a/server/lib/auth/oauth-model.ts
+++ b/server/lib/auth/oauth-model.ts
@@ -5,7 +5,6 @@ import { MOAuthClient } from '@server/types/models'
5import { MOAuthTokenUser } from '@server/types/models/oauth/oauth-token' 5import { MOAuthTokenUser } from '@server/types/models/oauth/oauth-token'
6import { MUser } from '@server/types/models/user/user' 6import { MUser } from '@server/types/models/user/user'
7import { pick } from '@shared/core-utils' 7import { pick } from '@shared/core-utils'
8import { UserRole } from '@shared/models/users/user-role'
9import { logger } from '../../helpers/logger' 8import { logger } from '../../helpers/logger'
10import { CONFIG } from '../../initializers/config' 9import { CONFIG } from '../../initializers/config'
11import { OAuthClientModel } from '../../models/oauth/oauth-client' 10import { OAuthClientModel } from '../../models/oauth/oauth-client'
@@ -13,6 +12,7 @@ import { OAuthTokenModel } from '../../models/oauth/oauth-token'
13import { UserModel } from '../../models/user/user' 12import { UserModel } from '../../models/user/user'
14import { findAvailableLocalActorName } from '../local-actor' 13import { findAvailableLocalActorName } from '../local-actor'
15import { buildUser, createUserAccountAndChannelAndPlaylist } from '../user' 14import { buildUser, createUserAccountAndChannelAndPlaylist } from '../user'
15import { ExternalUser } from './external-auth'
16import { TokensCache } from './tokens-cache' 16import { TokensCache } from './tokens-cache'
17 17
18type TokenInfo = { 18type TokenInfo = {
@@ -26,12 +26,7 @@ export type BypassLogin = {
26 bypass: boolean 26 bypass: boolean
27 pluginName: string 27 pluginName: string
28 authName?: string 28 authName?: string
29 user: { 29 user: ExternalUser
30 username: string
31 email: string
32 displayName: string
33 role: UserRole
34 }
35} 30}
36 31
37async function getAccessToken (bearerToken: string) { 32async function getAccessToken (bearerToken: string) {
@@ -219,16 +214,11 @@ export {
219 214
220// --------------------------------------------------------------------------- 215// ---------------------------------------------------------------------------
221 216
222async function createUserFromExternal (pluginAuth: string, options: { 217async function createUserFromExternal (pluginAuth: string, userOptions: ExternalUser) {
223 username: string 218 const username = await findAvailableLocalActorName(userOptions.username)
224 email: string
225 role: UserRole
226 displayName: string
227}) {
228 const username = await findAvailableLocalActorName(options.username)
229 219
230 const userToCreate = buildUser({ 220 const userToCreate = buildUser({
231 ...pick(options, [ 'email', 'role' ]), 221 ...pick(userOptions, [ 'email', 'role', 'adminFlags', 'videoQuota', 'videoQuotaDaily' ]),
232 222
233 username, 223 username,
234 emailVerified: null, 224 emailVerified: null,
@@ -238,7 +228,7 @@ async function createUserFromExternal (pluginAuth: string, options: {
238 228
239 const { user } = await createUserAccountAndChannelAndPlaylist({ 229 const { user } = await createUserAccountAndChannelAndPlaylist({
240 userToCreate, 230 userToCreate,
241 userDisplayName: options.displayName 231 userDisplayName: userOptions.displayName
242 }) 232 })
243 233
244 return user 234 return user