- return this.http.post(AuthService.BASE_TOKEN_URL, body.toString(), options)
- .map(this.restExtractor.extractDataGet)
- .map(res => {
- res.username = username;
- return res;
- })
- .flatMap(res => this.fetchUserInformations(res))
+ login (username: string, password: string) {
+ // Form url encoded
+ const body = new HttpParams().set('client_id', this.clientId)
+ .set('client_secret', this.clientSecret)
+ .set('response_type', 'code')
+ .set('grant_type', 'password')
+ .set('scope', 'upload')
+ .set('username', username)
+ .set('password', password)
+
+ const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')
+
+ return this.http.post<UserLogin>(AuthService.BASE_TOKEN_URL, body, { headers })
+ .map(res => Object.assign(res, { username }))
+ .flatMap(res => this.mergeUserInformation(res))