Skip to content

Instantly share code, notes, and snippets.

@gdyrrahitis

gdyrrahitis/auth.service.ts Secret

Created Aug 18, 2018
Embed
What would you like to do?
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
You can’t perform that action at this time.