'Angular Basic Token headers characters error UTF8
I am creating a basic token forthe process in angular. I am sendind this token in the headers section.But I get an error when I use characters like 'işğüç' in the name or password. I think it is releated to charset UTF 8 my error is.
return this.http.get<any>(apiHost + '/login',
{
headers: {
Authorization: this.createBasicAuthToken(name, password)
},
},
).pipe(map(response => {...}
createBasicAuthToken(name: String, password: String) {
return 'Basic ' + btoa(name+ ":" + password);
}
export class HttpInterceptorService implements HttpInterceptor {
constructor(private authenticationService: AuthenticationService) { }
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (this.authenticationService.isUserLoggedIn() && req.url.indexOf('login') === -1) {
const authReq = req.clone({
headers: new HttpHeaders({
'Authorization': `Basic ${window.btoa(this.authenticationService.getLoggedInUserName() + ":" + this.authenticationService.getLoggedInPassword())}`,
})
});
return next.handle(authReq);
}
else {
return next.handle(req);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
