I am trying to connect to Keyckloak to get the 'access_token' with angular. But I have this error :
Failed to load http://localhost:8080/auth/realms/demo/protocol/openid-connect/token: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 400.
I give you my code :
readonly ROOT_URL = 'http://localhost:8080/auth/realms/demo/protocol/openid-connect/token';
posts : any;
constructor(private http: HttpClient) {}
getToken() {
const data: Post = {
username: 'pierrecolart',
password: 'root',
grant_type: 'password',
client_id: 'admin-cli'
}
this.http
.post(
this.ROOT_URL,
data,
{headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')}
)
.map(res => res.json())
.subscribe(data => console.log(data))
}