Rocket.Chat icon indicating copy to clipboard operation
Rocket.Chat copied to clipboard

Keycloak integration (custom OAuth provider: openID protocol)

Open bakhtizin opened this issue 9 years ago • 6 comments

Rocket.Chat Version: 0.56.0 Running Instances: 1 DB Replicaset OpLog: Disabled Node Version: 4.8.1 - x64

Some additional info: ➔ Platform: linux
➔ Process Port: 3000
➔ Site URL: http://chat.inumio.com:3000 ➔ Doployed via provided docker image

After numerous configuration attempts, I cannot proceed any further. It's definitely has something to do with my lack of knowledge in js and js frameworks. Any help will be much appreciated. I believe that Rocket.Chat is keycloak compatible, there are several closed issues on this topic. I can see active session for user in keycloak administration console (user is authenticated), but redirect takes me back to Rocket.Chat login page.

I keep recieving following errors (taken from running container log):

{"line":"431","file":"oauth.js","message":"Error in OAuth Server: Failed to complete OAuth handshake with keycloak at http://localhost:8080/auth/realms/RocketChat/protocol/openid-connect/token. connect ECONNREFUSED 127.0.0.1:8080","time":{"$date":1499265254399},"level":"warn"}

And it is followed by:

Exception while invoking method 'login' Error: Failed to complete OAuth handshake with keycloak at http://localhost:8080/auth/realms/RocketChat/protocol/openid-connect/token. connect ECONNREFUSED 127.0.0.1:8080
  at CustomOAuth.getAccessToken (/app/bundle/programs/server/packages/rocketchat_custom-oauth.js:157:17)
  at Object.handleOauthRequest (/app/bundle/programs/server/packages/rocketchat_custom-oauth.js:226:28)
  at OAuth._requestHandlers.(anonymous function) (packages/oauth2.js:27:31)
  at middleware (packages/oauth.js:203:5)
  at packages/oauth.js:176:5

My configurations for Custom OAuth Keycloak look like this:

Enable: True
URL: http://localhost:8080/auth/
Token Path: http://localhost:8080/auth/realms/RocketChat/protocol/openid-connect/token
Identity Path: http://localhost:8080/auth/realms/RocketChat/protocol/openid-connect/userinfo
Authorize Path: http://localhost:8080/auth/realms/RocketChat/protocol/openid-connect/auth
Scope: openid
Token Sent Via: Payload
Id: rocket
......
Username field: username

bakhtizin avatar Jul 05 '17 15:07 bakhtizin

@bakhtizin @MartinSchoeler can you please help me setting up Identity Server or if you can guide me how can i write a custom package to handle this.

I get the same error as mentioned by @bakhtizin after some digging I found that Dynabic.Crocket expect a query param code= while IdentityServer is posting "id_token" in body which cann't be accessed in rocket_custom_oauth package via the query string hence an empty token causes the error.

assadvirgo avatar Jul 17 '17 06:07 assadvirgo

Could we have a WeChat login, so we could use it in China,thanks a lot

ottomMT avatar Jul 26 '17 11:07 ottomMT

After several attempt, I've finally found a solution to my issue.

Just read the contents of the existing tickets carefully!

Thus, the problem was (of course) my misconfiguration and (of course) it was already answered! In order to get the things working following should be set:

  1. Token Path: /realms/{realm_name}/protocol/openid-connect/token
  2. Identity Path: /realms/{realm_name}/protocol/openid-connect/userinfo
  3. Authorize Path: /realms/{realm_name}/protocol/openid-connect/auth
  4. Token Sent Via: Header
  5. Id: Correct Client ID from Keycloak administration console
  6. Secret: Configure Rocket.Chat client as a confidential client and paste here the secret
  7. Username field: preferred_username

bakhtizin avatar Aug 11 '17 13:08 bakhtizin

I am trying to integrate the Rocket chat with the keycloak. My Rocket Chat is 0.63.3v . And my Keycloak is 4.0.0v.

My Keycloak configuration: Here sample is my realm name.

id : rocketchat
Client Protocol: Openind Connect
Access Type : Confidential
Valid Redirect URIs : http://IP_Address:port/_oauth/keycloak
Standard Flow Enabled:on
Implicit Flow Enabled:on
Direct Access Grants Enabled :on

Rocket Chat OAuth Configuration

URL: http://IP_Address/auth
Token Path : /realms/sample/protocol/openid-connect/token
Identity Path: /realms/sample/protocol/openid-connect/userinfo
Authorize Path: /realms/sample/protocol/openid-connect/auth
Scope: openid
Token Sent Via: header
Id: rocketchat
Secret: keycloak secret id

But after this configuration the rocket chat login page does not redirect to keycloak page. And i am not seeing any login rocket chat and keycloak.

How to solve my problem.Any one know the solution, please tell me

ghost avatar May 14 '18 03:05 ghost

Finally i was find solution for rocket chat and keycloak integration. Create the user in keycloack in sample realm. and create the password for user. Here i am not write any name for username field in rocket chat keycloak custom oauth. Here, when i am hitting the rocket chat URL it will never redirect to keycloak login page. Instead of redirection. i can seen the keycloak login button in the rocket chat login screen.

image

The blue color button is gateway of keycloak login page.

ghost avatar May 14 '18 09:05 ghost

What is the solution to integrate keycloak with rocketchat

arunodhayam10d avatar Oct 22 '21 11:10 arunodhayam10d