jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.56k stars 4.02k forks source link

"sign in" links to "keycloak:9080/..." instead of "localhost:9080/..." in Docker #6722

Closed ThomasWilhelmUR closed 6 years ago

ThomasWilhelmUR commented 6 years ago
Overview of the issue

In a microservice environment running in docker using the new Keycloak feature, the sign in links will take you here: http://keycloak:9080/auth/realms/jhipster/protocol/openid-connect/auth?client_id=web_app&redirect_uri=http://localhost:8080/login&response_type=code&scope=openid%20profile%20email&state=2HNh2B

Motivation for or Use Case

Testing the new Keycloak integration.

Reproduce the error

How I did it / how to reproduce:

  1. Create new microservice using keycloak
  2. Create new gateway using keycloak
  3. Create a dummy entity (like "foo") and regenerate.
  4. Run the docker-compose subgenerator
  5. Start all of the apps using "docker-compose up -d"
Related issues

When changing "keycloak:9080/" to "localhost:9080/" there is another error.

6723

Suggest a Fix

Clicking "sign in" in the gateway should take you to "localhost:9080".

JHipster Version(s)

4.10.2

JHipster configuration

Service:

{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "en.something",
      "nativeLanguage": "de"
    },
    "jhipsterVersion": "4.10.2",
    "baseName": "service",
    "packageName": "en.something",
    "packageFolder": "en/something",
    "serverPort": "8081",
    "authenticationType": "oauth2",
    "hibernateCache": "hazelcast",
    "clusteredHttpSession": false,
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "postgresql",
    "prodDatabaseType": "postgresql",
    "searchEngine": "elasticsearch",
    "messageBroker": false,
    "serviceDiscoveryType": "eureka",
    "buildTool": "maven",
    "enableSocialSignIn": false,
    "enableSwaggerCodegen": false,
    "jwtSecretKey": "1372d952e81cee4ed366b7d48c803dd3904c35cd",
    "enableTranslation": true,
    "applicationType": "microservice",
    "testFrameworks": [],
    "jhiPrefix": "jhi",
    "nativeLanguage": "de",
    "languages": [
      "de"
    ],
    "clientPackageManager": "yarn",
    "skipClient": true,
    "skipUserManagement": true
  }
}

Gateway:

{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "en.something",
      "nativeLanguage": "de",
      "microservicePath": "../service"
    },
    "jhipsterVersion": "4.10.2",
    "baseName": "gateway",
    "packageName": "en.something",
    "packageFolder": "en/something",
    "serverPort": "8080",
    "authenticationType": "oauth2",
    "hibernateCache": "hazelcast",
    "clusteredHttpSession": false,
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "postgresql",
    "prodDatabaseType": "postgresql",
    "searchEngine": "elasticsearch",
    "messageBroker": false,
    "serviceDiscoveryType": "eureka",
    "buildTool": "maven",
    "enableSocialSignIn": false,
    "enableSwaggerCodegen": false,
    "clientFramework": "angularX",
    "useSass": true,
    "clientPackageManager": "yarn",
    "applicationType": "gateway",
    "testFrameworks": [],
    "jhiPrefix": "jhi",
    "enableTranslation": true,
    "nativeLanguage": "de",
    "languages": [
      "de",
      "en"
    ]
  }
}
Entity configuration(s) entityName.json files generated in the .jhipster directory
Foo.json
{
    "fluentMethods": true,
    "relationships": [],
    "fields": [
        {
            "fieldName": "fooname",
            "fieldType": "String"
        }
    ],
    "changelogDate": "20171123142052",
    "dto": "no",
    "service": "no",
    "entityTableName": "foo",
    "jpaMetamodelFiltering": false,
    "pagination": "no",
    "microserviceName": "service",
    "searchEngine": "elasticsearch"
}
Browsers and Operating System

Windows, Chrome/FF

mraible commented 6 years ago

Yes, this is expected. You have to create a hosts entry for keycloak that points to 127.0.0.1 and everything will work. We tried to come up with a better solution, but failed to do so.

On Nov 23, 2017, at 10:34, TW notifications@github.com wrote:

Overview of the issue

In a microservice environment running in docker using the new Keycloak feature, the sign in links will take you here: http://keycloak:9080/auth/realms/jhipster/protocol/openid-connect/auth?client_id=web_app&redirect_uri=http://localhost:8080/login&response_type=code&scope=openid%20profile%20email&state=2HNh2B

Motivation for or Use Case

Testing the new Keycloak integration.

Reproduce the error

How I did it / how to reproduce:

Create new microservice using keycloak Create new gateway using keycloak Create a dummy entity (like "foo") and regenerate. Run the docker-compose subgenerator Start all of the apps using "docker-compose up -d" Related issues

When changing "keycloak:9080/" to "localhost:9080/" there is another error. to be posted.

Suggest a Fix

Clicking "sign in" in the gateway should take you to "localhost:9080".

JHipster Version(s)

4.10.2

JHipster configuration

Service:

{ "generator-jhipster": { "promptValues": { "packageName": "en.something", "nativeLanguage": "de" }, "jhipsterVersion": "4.10.2", "baseName": "service", "packageName": "en.something", "packageFolder": "en/something", "serverPort": "8081", "authenticationType": "oauth2", "hibernateCache": "hazelcast", "clusteredHttpSession": false, "websocket": false, "databaseType": "sql", "devDatabaseType": "postgresql", "prodDatabaseType": "postgresql", "searchEngine": "elasticsearch", "messageBroker": false, "serviceDiscoveryType": "eureka", "buildTool": "maven", "enableSocialSignIn": false, "enableSwaggerCodegen": false, "jwtSecretKey": "1372d952e81cee4ed366b7d48c803dd3904c35cd", "enableTranslation": true, "applicationType": "microservice", "testFrameworks": [], "jhiPrefix": "jhi", "nativeLanguage": "de", "languages": [ "de" ], "clientPackageManager": "yarn", "skipClient": true, "skipUserManagement": true } } Gateway:

{ "generator-jhipster": { "promptValues": { "packageName": "en.something", "nativeLanguage": "de", "microservicePath": "../service" }, "jhipsterVersion": "4.10.2", "baseName": "gateway", "packageName": "en.something", "packageFolder": "en/something", "serverPort": "8080", "authenticationType": "oauth2", "hibernateCache": "hazelcast", "clusteredHttpSession": false, "websocket": false, "databaseType": "sql", "devDatabaseType": "postgresql", "prodDatabaseType": "postgresql", "searchEngine": "elasticsearch", "messageBroker": false, "serviceDiscoveryType": "eureka", "buildTool": "maven", "enableSocialSignIn": false, "enableSwaggerCodegen": false, "clientFramework": "angularX", "useSass": true, "clientPackageManager": "yarn", "applicationType": "gateway", "testFrameworks": [], "jhiPrefix": "jhi", "enableTranslation": true, "nativeLanguage": "de", "languages": [ "de", "en" ] } } Entity configuration(s) entityName.json files generated in the .jhipster directory

Foo.json { "fluentMethods": true, "relationships": [], "fields": [ { "fieldName": "fooname", "fieldType": "String" } ], "changelogDate": "20171123142052", "dto": "no", "service": "no", "entityTableName": "foo", "jpaMetamodelFiltering": false, "pagination": "no", "microserviceName": "service", "searchEngine": "elasticsearch" } Browsers and Operating System

Windows, Chrome/FF

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

ThomasWilhelmUR commented 6 years ago

Thank you. Can you point me to the disccusion? (I looked around in lots of issues but didn't see it before, thanks!)

Could the referenced issue #6723 come down to this too?

Edit: In application.yaml the localhost is hardcoded:

security:
    basic:
        enabled: false
    oauth2:
        client:
            access-token-uri: http://localhost:9080/auth/realms/jhipster/protocol/openid-connect/token
            user-authorization-uri: http://localhost:9080/auth/realms/jhipster/protocol/openid-connect/auth
            client-id: web_app
            client-secret: web_app
            client-authentication-scheme: form
            scope: openid profile email
        resource:
            filter-order: 3
            user-info-uri: http://localhost:9080/auth/realms/jhipster/protocol/openid-connect/userinfo
            token-info-uri: http://localhost:9080/auth/realms/jhipster/protocol/openid-connect/token/introspect
            prefer-token-info: false
            jwt:
                key-uri: http://localhost:9080/auth/realms/jhipster
jdubois commented 6 years ago

Yes, what @mraible says is in the documentation -> closing this as this is not a bug.

Then I know the documentation isn't good enough, we have an opened ticket for that, but we just lack the time to write it.

ThomasWilhelmUR commented 6 years ago

I did some digging and finally found it - I am glad you will be improving the documentation in this regard. Thanks.

This fixed #6723

issamm commented 6 years ago

Hi @ThomasWilhelmUR , why don't you just put the answer and what you found ?

sslgeorge commented 4 years ago

@ThomasWilhelmUR and @jdubois Really, why don't you put the answer here, I am having the exact issue and I have to dig around

Tcharl commented 4 years ago

Hi, @sslgeorge @issamm ,

@mraible told what to do in order to make it work: edit your /etc/hosts file and add an entry like 127.0.0.1 keycloak

pascalgrimaud commented 4 years ago

@issamm @sslgeorge : just check our website -> https://www.jhipster.tech/docker-compose/#-keycloak