I'm using Angular 5 front-end & Laravel 5.6 Backend as Rest API
Now I'm trying to get Access Token using:
const url = 'http://127.0.0.1:8000/oauth/token' ;
const body = JSON.stringify({
'client_id' : '8',
'client_secret': 'nMfgx0XrlfvImZK1vqu7PucCaaezDZofJOhTLh4m',
'grant_type' : 'password',
'username' : 'admin',
'password' : '0a09943d507c591ae7269042a57db16ac9a2b971'
});
const httpOptions = {
headers: new HttpHeaders({
'Accept' : 'application/json',
'Content-Type': 'application/json'
}
)
};
const res = this.http.post<any>(url, body, httpOptions)
.subscribe(myres => { console.log(myres); }) ;
It's working fine on PostMan but With Angular Show this Error:
login:1 Failed to load http://127.0.0.1:8000/oauth/token: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
I heard should use somthing called :
header('Access-Control-Allow-Origin', '*')ce