aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-05-18 11:02:40 +0200
committerChocobozzz <me@florianbigard.com>2018-05-22 09:17:20 +0200
commitcd4d7a2ca868209fb1e2dbd790c1e5d6cca77e86 (patch)
treea8d9e219c893551f669a3de37ae0ee91a6c0f7cd /client/src/app
parentb4e5942ca79b8f5702c80197ec40eab8fa053a24 (diff)
downloadPeerTube-cd4d7a2ca868209fb1e2dbd790c1e5d6cca77e86.tar.gz
PeerTube-cd4d7a2ca868209fb1e2dbd790c1e5d6cca77e86.tar.zst
PeerTube-cd4d7a2ca868209fb1e2dbd790c1e5d6cca77e86.zip
Fix peertube with google bot
Diffstat (limited to 'client/src/app')
-rw-r--r--client/src/app/core/auth/auth.service.ts20
-rw-r--r--client/src/app/shared/misc/utils.ts10
2 files changed, 21 insertions, 9 deletions
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'
11import { RestExtractor } from '../../shared/rest' 11import { RestExtractor } from '../../shared/rest'
12import { AuthStatus } from './auth-status.model' 12import { AuthStatus } from './auth-status.model'
13import { AuthUser } from './auth-user.model' 13import { AuthUser } from './auth-user.model'
14import { objectToUrlEncoded } from '@app/shared/misc/utils'
14 15
15interface UserLoginWithUsername extends UserLogin { 16interface UserLoginWithUsername extends UserLogin {
16 access_token: string 17 access_token: string
@@ -113,17 +114,18 @@ export class AuthService {
113 114
114 login (username: string, password: string) { 115 login (username: string, password: string) {
115 // Form url encoded 116 // Form url encoded
116 const body = new URLSearchParams() 117 const body = {
117 body.set('client_id', this.clientId) 118 client_id: this.clientId,
118 body.set('client_secret', this.clientSecret) 119 client_secret: this.clientSecret,
119 body.set('response_type', 'code') 120 response_type: 'code',
120 body.set('grant_type', 'password') 121 grant_type: 'password',
121 body.set('scope', 'upload') 122 scope: 'upload',
122 body.set('username', username) 123 username,
123 body.set('password', password) 124 password
125 }
124 126
125 const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded') 127 const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')
126 return this.http.post<UserLogin>(AuthService.BASE_TOKEN_URL, body.toString(), { headers }) 128 return this.http.post<UserLogin>(AuthService.BASE_TOKEN_URL, objectToUrlEncoded(body), { headers })
127 .pipe( 129 .pipe(
128 map(res => Object.assign(res, { username })), 130 map(res => Object.assign(res, { username })),
129 mergeMap(res => this.mergeUserInformation(res)), 131 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 <A, B> (target: A, source: B) {
55 return Object.assign({}, target, source) 55 return Object.assign({}, target, source)
56} 56}
57 57
58function objectToUrlEncoded (obj: any) {
59 const str: string[] = []
60 for (const key of Object.keys(obj)) {
61 str.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]))
62 }
63
64 return str.join('&')
65}
66
58// Thanks: https://gist.github.com/ghinda/8442a57f22099bdb2e34 67// Thanks: https://gist.github.com/ghinda/8442a57f22099bdb2e34
59function objectToFormData (obj: any, form?: FormData, namespace?: string) { 68function objectToFormData (obj: any, form?: FormData, namespace?: string) {
60 let fd = form || new FormData() 69 let fd = form || new FormData()
@@ -100,6 +109,7 @@ function isInMobileView () {
100} 109}
101 110
102export { 111export {
112 objectToUrlEncoded,
103 getParameterByName, 113 getParameterByName,
104 populateAsyncUserVideoChannels, 114 populateAsyncUserVideoChannels,
105 getAbsoluteAPIUrl, 115 getAbsoluteAPIUrl,