I have this auth.interceptor.ts
import { Injectable } from "@angular/core";
import { HttpInterceptor, HttpRequest, HttpHandler } from "@angular/common/http";
import { TokenService } from "../shared/token.service";
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
constructor(private tokenService: TokenService) { }
intercept(req: HttpRequest<any>, next: HttpHandler) {
const accessToken = this.tokenService.getToken();
req = req.clone({
setHeaders: {
Authorization: "Bearer " accessToken
}
});
return next.handle(req);
}
}
it is called in app.module.ts and other module.ts file
import { AuthInterceptor } from './shared/auth.interceptor';
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: AuthInterceptor,
multi: true
}
],
but i can access all the laravel apis without token
Calling api:
this.http.post(this.baseUrl 'api/auth/load-data', formData).subscribe(result => {
this.lists=result;
},(error) => {
});
I want to secure my laravel api
CodePudding user response:
have you uesed laravel passport? with that package you can secure your laravel apis
CodePudding user response:
You should use the passport package in order to secure your APIs, this is the doc from the Laravel website:
https://laravel.com/docs/8.x/passport
I think its straight forward