From cd4d7a2ca868209fb1e2dbd790c1e5d6cca77e86 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 18 May 2018 11:02:40 +0200 Subject: Fix peertube with google bot --- client/src/app/core/auth/auth.service.ts | 20 +++++++++++--------- client/src/app/shared/misc/utils.ts | 10 ++++++++++ 2 files changed, 21 insertions(+), 9 deletions(-) (limited to 'client/src/app') diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts index 4b388d7be..4213da20c 100644 --- a/client/src/app/core/auth/auth.service.ts +++ b/client/src/app/core/auth/auth.service.ts @@ -11,6 +11,7 @@ import { environment } from '../../../environments/environment' import { RestExtractor } from '../../shared/rest' import { AuthStatus } from './auth-status.model' import { AuthUser } from './auth-user.model' +import { objectToUrlEncoded } from '@app/shared/misc/utils' interface UserLoginWithUsername extends UserLogin { access_token: string @@ -113,17 +114,18 @@ export class AuthService { login (username: string, password: string) { // Form url encoded - const body = new URLSearchParams() - body.set('client_id', this.clientId) - body.set('client_secret', this.clientSecret) - body.set('response_type', 'code') - body.set('grant_type', 'password') - body.set('scope', 'upload') - body.set('username', username) - body.set('password', password) + const body = { + client_id: this.clientId, + client_secret: this.clientSecret, + response_type: 'code', + grant_type: 'password', + scope: 'upload', + username, + password + } const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded') - return this.http.post(AuthService.BASE_TOKEN_URL, body.toString(), { headers }) + return this.http.post(AuthService.BASE_TOKEN_URL, objectToUrlEncoded(body), { headers }) .pipe( map(res => Object.assign(res, { username })), mergeMap(res => this.mergeUserInformation(res)), diff --git a/client/src/app/shared/misc/utils.ts b/client/src/app/shared/misc/utils.ts index b9aa223cf..79c93c1b3 100644 --- a/client/src/app/shared/misc/utils.ts +++ b/client/src/app/shared/misc/utils.ts @@ -55,6 +55,15 @@ function immutableAssign (target: A, source: B) { return Object.assign({}, target, source) } +function objectToUrlEncoded (obj: any) { + const str: string[] = [] + for (const key of Object.keys(obj)) { + str.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key])) + } + + return str.join('&') +} + // Thanks: https://gist.github.com/ghinda/8442a57f22099bdb2e34 function objectToFormData (obj: any, form?: FormData, namespace?: string) { let fd = form || new FormData() @@ -100,6 +109,7 @@ function isInMobileView () { } export { + objectToUrlEncoded, getParameterByName, populateAsyncUserVideoChannels, getAbsoluteAPIUrl, -- cgit v1.2.3