-
-
Save gdyrrahitis/6705b56cf2e6671fe6fdedece4fe762b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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