I am evaluating some IAM products and have encountered a problem with CORS using Keycloak's RealmResourceProvider. The goal is to write an angular4 client that can create users and manage groups using Keycloak's REST interface.
server side:
I tried to implement the Rest interface with the RealmResourceProvider interface so that I can access Realm and User Data as easily as possible. I followed the Beercloak example (github.com/dteleguin/beercloak) and got it working, but without a special topic (only REST-Resources). My own application is packaged as a Jar. I managed to call this facade through the REST Client, and it worked (first called localhost: 8080 / auth / realms / master / protocol / openid-connect / token, and then filled the token in the authorization header).
keycloak-configuration
, but if I check it through the browser, I will need to turn on Cross-Origin-Ressource-Sharing. To do this, I added the "enable-cors" attribute to "keycloak.json" in the server application:
{
"realm": "master",
"auth-server-url": "http://localhost:8080/auth",
"ssl-required": "external",
"resource": "pharmacyRessource",
"public-client": true,
"enable-cors": true
}
In addition, I created a client in Keycloak Admin.
Client configuration
:
angular Mohuks ng2-keyclayak github.com/mohuk/ng2-keycloak/blob/master/src/keycloak.service.ts, accesstoken. - .
, GET , - Access-Control-Allow-Origin:
401
Keycloak.json, keycloak-client javascript, :
{
"realm": "master",
"auth-server-url": "http://localhost:8080/auth",
"ssl-required": "external",
"resource": "pharmacyRessource",
"public-client": true
}
:
- CORS, ,
keycloak.
- @OPTIONS CORSE
. , .
- .war,
/, .
hub.docker.com/r/jboss/keycloak/