+
+ private _login (options: LoginOptions) {
+ const { client = this.server.store.client, user = this.server.store.user, otpToken } = options
+ const path = '/api/v1/users/token'
+
+ const body = {
+ client_id: client.id,
+ client_secret: client.secret,
+ username: user.username,
+ password: user.password ?? 'password',
+ response_type: 'code',
+ grant_type: 'password',
+ scope: 'upload'
+ }
+
+ const headers = otpToken
+ ? { 'x-peertube-otp': otpToken }
+ : {}
+
+ return this.postBodyRequest({
+ ...options,
+
+ path,
+ headers,
+ requestType: 'form',
+ fields: body,
+ implicitToken: false,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ private unwrapLoginBody (body: any) {
+ return body as { access_token: string, refresh_token: string } & PeerTubeProblemDocument
+ }