# Angular post return 401. Oauth2

**URL:** <https://forum.ionicframework.com/t/angular-post-return-401-oauth2/102346>\
**Category:** ionic-v3\
**Created:** [August 17, 2017, 3:47pm UTC](https://forum.ionicframework.com/t/angular-post-return-401-oauth2/102346 "2017-08-17T15:47:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kam3o](https://avatars.discourse-cdn.com/v4/letter/k/51bf81/32.png) [@kam3o](https://forum.ionicframework.com/u/kam3o)\
**Post date:** [August 17, 2017, 3:47pm UTC](https://forum.ionicframework.com/t/angular-post-return-401-oauth2/102346/1 "2017-08-17T15:47:09Z")

</div>

I want use oauth2 in my ionic app. but i get error:

> Failed to load resource: the server responded with a status of 401 ()
> 
> Error: Http failure response for [http://localhost:8080/oauth/token:](http://localhost:8080/oauth/token:) 401 OK

Response:

```auto
{"timestamp":1502983544253,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource","path":"/oauth/token"}

```

Angular function:

```auto
login(username, password) : Observable<any> {

 let params: HttpParams = new HttpParams();
 params.set('username', username);
 params.set('password', password);
 params.set('client_id', this.clientId);
 params.set('client_secret', this.clientSecret);
 params.set('grant_type', 'password');

 let headers = new HttpHeaders();
 headers.set('Content-Type', 'application/x-www-form-urlencoded');

 return this.http.post(this.EndPointUrl, {
   params:params
 }, { headers:headers}).map(this.handleData).
   catch(this.handleError); }

```

I can get token using, PostMan and curl, CORS in my server is enabled for this endpoint so i think the auth server works properly.

Does anyone know what I’m doing wrong?
