diff options
Diffstat (limited to 'client/src/app')
-rw-r--r-- | client/src/app/core/auth/auth.service.ts | 20 | ||||
-rw-r--r-- | client/src/app/shared/misc/utils.ts | 10 |
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' | |||
11 | import { RestExtractor } from '../../shared/rest' | 11 | import { RestExtractor } from '../../shared/rest' |
12 | import { AuthStatus } from './auth-status.model' | 12 | import { AuthStatus } from './auth-status.model' |
13 | import { AuthUser } from './auth-user.model' | 13 | import { AuthUser } from './auth-user.model' |
14 | import { objectToUrlEncoded } from '@app/shared/misc/utils' | ||
14 | 15 | ||
15 | interface UserLoginWithUsername extends UserLogin { | 16 | interface 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 | ||
58 | function 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 |
59 | function objectToFormData (obj: any, form?: FormData, namespace?: string) { | 68 | function 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 | ||
102 | export { | 111 | export { |
112 | objectToUrlEncoded, | ||
103 | getParameterByName, | 113 | getParameterByName, |
104 | populateAsyncUserVideoChannels, | 114 | populateAsyncUserVideoChannels, |
105 | getAbsoluteAPIUrl, | 115 | getAbsoluteAPIUrl, |