-import { PeerTubeRequestError } from '@server/helpers/requests'
-import { HttpStatusCode } from '@shared/core-utils'
-import { PeerTubeProblemDocument } from '@shared/models'
+import { HttpStatusCode, PeerTubeProblemDocument } from '@shared/models'
import { unwrapBody } from '../requests'
import { AbstractCommand, OverrideCommandOptions } from '../shared'
login (options: OverrideCommandOptions & {
client?: { id?: string, secret?: string }
- user?: { username: string, password: string }
+ user?: { username: string, password?: string }
} = {}) {
- const { client = this.server.client, user = this.server.user } = options
+ const { client = this.server.store.client, user = this.server.store.user } = options
const path = '/api/v1/users/token'
const body = {
client_id: client.id,
client_secret: client.secret,
username: user.username,
- password: user.password,
+ password: user.password ?? 'password',
response_type: 'code',
grant_type: 'password',
scope: 'upload'
...options,
path,
- type: 'form',
+ requestType: 'form',
fields: body,
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200
}))
}
- getAccessToken (user?: { username: string, password: string }): Promise<string>
- getAccessToken (username: string, password: string): Promise<string>
- async getAccessToken (arg1?: { username: string, password: string } | string, password?: string) {
- let user: { username: string, password: string }
+ getAccessToken (arg1?: { username: string, password?: string }): Promise<string>
+ getAccessToken (arg1: string, password?: string): Promise<string>
+ async getAccessToken (arg1?: { username: string, password?: string } | string, password?: string) {
+ let user: { username: string, password?: string }
- if (!arg1) user = this.server.user
+ if (!arg1) user = this.server.store.user
else if (typeof arg1 === 'object') user = arg1
else user = { username: arg1, password }
return body.access_token
} catch (err) {
- throw new Error('Cannot authenticate. Please check your username/password.')
+ throw new Error(`Cannot authenticate. Please check your username/password. (${err})`)
}
}
const path = '/api/v1/users/token'
const body = {
- client_id: this.server.client.id,
- client_secret: this.server.client.secret,
+ client_id: this.server.store.client.id,
+ client_secret: this.server.store.client.secret,
username: username,
response_type: 'code',
grant_type: 'password',
...options,
path,
- type: 'form',
+ requestType: 'form',
fields: body,
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200
...options,
path,
- type: 'form',
+ requestType: 'form',
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200
}))
const path = '/api/v1/users/token'
const body = {
- client_id: this.server.client.id,
- client_secret: this.server.client.secret,
+ client_id: this.server.store.client.id,
+ client_secret: this.server.store.client.secret,
refresh_token: options.refreshToken,
response_type: 'code',
grant_type: 'refresh_token'
...options,
path,
- type: 'form',
+ requestType: 'form',
fields: body,
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200