Error loading discovery document and blocked by CORS policy

I am using the npm package “angular-oauth2-oidc 13.0.1” for OIDC authentication with InitCodeFlow and loadDiscoveryDocumentAndTryLogin with below auth config. But it throw the below errors and I have set the origin in keycloak client dashboard to specific url as well as ‘*’.

  let authConfig = new AuthConfig();
        authConfig.loginUrl = "https://{Host}/realms/{real-name}/protocol/openid-connect/auth";
        authConfig.issuer = "https://{Host}/realms/{real-name}/";
        authConfig.skipIssuerCheck = loginProvider.additionalParams['ValidateIssuer'] === 'false';
        authConfig.clientId = loginProvider.clientId;
        authConfig.responseType = 'code';
        authConfig.redirectUri = window.location.origin + '/account/login';
        authConfig.scope = 'openid profile email';  
        return authConfig;

Error Message:

Response Message:

message: "Http failure response for https://{Host}/realms/{real-name}/.well-known/openid-configuration: 0 Unknown Error"
name: "HttpErrorResponse"
ok: false
status: 0
statusText: "Unknown Error"
url: "https://{Host}/realms/{real-name}/.well-known/openid-configuration"

Your client seems to be adding the “pragma” header to the requests. Keycloak is very picky on that topic, please see this for more info: [CORS] Allow Access-Control-Allow-Headers customization · Issue #12682 · keycloak/keycloak · GitHub

1 Like