Skip to content

Instantly share code, notes, and snippets.

@gdyrrahitis
Created August 18, 2018 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdyrrahitis/6705b56cf2e6671fe6fdedece4fe762b to your computer and use it in GitHub Desktop.
Save gdyrrahitis/6705b56cf2e6671fe6fdedece4fe762b to your computer and use it in GitHub Desktop.
authenticate(username: string, password: string): Observable<any> {
let headers = new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' });
let body = new URLSearchParams();
body.set('username', username);
body.set('password', password);
body.set('grant_type', "password");
body.set('client_id', "angular.client");
body.set('client_secret', "secret");
return this.http.post<any>(this.url, body.toString(), {
headers: headers
}).pipe(
map(jwt => {
if (jwt && jwt.access_token) {
localStorage.setItem('token', JSON.stringify(jwt))
}
})
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment