I am developing an web app and I am using angular for front-end and keycloak for security.
I am using the following packages on angular side:
On front-end (angular app) I am trying to retrieve the user details using the following service:
import { Injectable } from '@angular/core';
import { KeycloakService } from 'keycloak-angular';
@Injectable({
providedIn: 'root'
})
export class JwtDecoderService {
public profile;
getUserProfile(){
this.keycloakService.loadUserProfile().then(x => this.profile = x)
}
constructor(public keycloakService: KeycloakService) {}
}
As I think, the call to the loadUserProfile() initiates a GET request to a client (account) of the keycloak server.
I get a CORS error message as a response, see below:
I have tried to add localhost:4200 as Web Origins for the clients used, the client configured as mine on angular part is newClient, nevertheless the above request is targeting the account client.
In the end I put * as web origin for all clients involved both newClient and account.
Here are my list of clients:
As I mentioned this is the client I have indicated in angular:
export const environment = {
production: false,
keycloakConfig: {
clientId: 'newClient',
realm: 'SportEmploy',
url: 'http://localhost:8083/auth'
}
};
account client configuration: 1.
I have tried to put into WebOrigins of the both clients variations of http://localhost:4200/ http://localhost:4200 http://localhost:4200/* + and * , anything of this did not work.
This is how I start keycloak on angular side:
import {KeycloakService, KeycloakOptions} from 'keycloak-angular'
import { environment } from './environments/environment'
export function initializer(keycloak: KeycloakService): () => Promise<any> {
const options: KeycloakOptions = {
config: environment.keycloakConfig
};
return (): Promise<any> => keycloak.init(options);
}
Any ideas what could be wrong in my keycloak config ?