OCA / server-auth

https://odoo-community.org/psc-teams/tools-30
GNU Affero General Public License v3.0
145 stars 396 forks source link

odoo.addons.auth_keycloak.exceptions.OAuthError: Not Found #184

Closed NicolasDEVOUGE closed 1 year ago

NicolasDEVOUGE commented 4 years ago

Hello,

I want to use keycloak with Odoo, I have configured the momdule like this 👍 image

And keycloak like this :

image

When I click on login page, I'm redirected to Keycloak, without error :

`2020-04-10 11:26:16,236 DEBUG [org.keycloak.services.scheduled.ScheduledTaskRunner] (Timer-2) Executed scheduled task AbstractLastSessionRefreshStoreFactory$$Lambda$841/1490485563 2020-04-10 11:26:20,762 DEBUG [io.undertow.request] (default I/O-1) Matched prefix path /auth for path /auth/realms/master/protocol/openid-connect/auth 2020-04-10 11:26:20,763 DEBUG [io.undertow.request.security] (default task-75) Attempting to authenticate /auth/realms/master/protocol/openid-connect/auth, authentication required: false 2020-04-10 11:26:20,763 DEBUG [io.undertow.request.security] (default task-75) Authentication outcome was NOT_ATTEMPTED with method io.undertow.security.impl.CachedAuthenticatedSessionMechanism@20ff4420 for /auth/realms/master/protocol/openid-connect/auth 2020-04-10 11:26:20,763 DEBUG [io.undertow.request.security] (default task-75) Authentication result was ATTEMPTED for /auth/realms/master/protocol/openid-connect/auth 2020-04-10 11:26:20,763 DEBUG [org.keycloak.transaction.JtaTransactionWrapper] (default task-75) new JtaTransactionWrapper 2020-04-10 11:26:20,764 DEBUG [org.keycloak.transaction.JtaTransactionWrapper] (default task-75) was existing? false 2020-04-10 11:26:20,764 DEBUG [org.jboss.resteasy.resteasy_jaxrs.i18n] (default task-75) RESTEASY002315: PathInfo: /realms/master/protocol/openid-connect/auth 2020-04-10 11:26:20,765 DEBUG [org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl] (default task-75) Hibernate RegisteredSynchronization successfully registered with JTA platform 2020-04-10 11:26:20,766 DEBUG [org.keycloak.services.util.CookieHelper] (default task-75) {1} cookie found in the requests header 2020-04-10 11:26:20,766 DEBUG [org.keycloak.services.util.CookieHelper] (default task-75) {1} cookie found in the cookies field 2020-04-10 11:26:20,766 DEBUG [org.keycloak.services.managers.AuthenticationSessionManager] (default task-75) Found AUTH_SESSION_ID cookie with value a18e32c3-4ff4-45a5-8bcc-606b5c95f4c2.d-keycloack 2020-04-10 11:26:20,767 DEBUG [org.keycloak.services.util.CookieHelper] (default task-75) {1} cookie found in the requests header 2020-04-10 11:26:20,767 DEBUG [org.keycloak.services.util.CookieHelper] (default task-75) {1} cookie found in the cookies field 2020-04-10 11:26:20,767 DEBUG [org.keycloak.services.managers.AuthenticationSessionManager] (default task-75) Found AUTH_SESSION_ID cookie with value a18e32c3-4ff4-45a5-8bcc-606b5c95f4c2.d-keycloack 2020-04-10 11:26:20,767 DEBUG [org.keycloak.models.sessions.infinispan.InfinispanUserSessionProvider] (default task-75) getUserSessionWithPredicate(a18e32c3-4ff4-45a5-8bcc-606b5c95f4c2): remote cache not available 2020-04-10 11:26:20,768 DEBUG [org.keycloak.protocol.AuthorizationEndpointBase] (default task-75) Sent request to authz endpoint. We don't have root authentication session with ID 'a18e32c3-4ff4-45a5-8bcc-606b5c95f4c2' but we have userSession.Re-created root authentication session with same ID. Client is: odoo . New authentication session tab ID: W1rlGRsrYjQ 2020-04-10 11:26:20,770 DEBUG [org.keycloak.authentication.AuthenticationProcessor] (default task-75) AUTHENTICATE 2020-04-10 11:26:20,770 DEBUG [org.keycloak.authentication.AuthenticationProcessor] (default task-75) AUTHENTICATE ONLY 2020-04-10 11:26:20,770 DEBUG [org.keycloak.authentication.DefaultAuthenticationFlow] (default task-75) processFlow: browser 2020-04-10 11:26:20,770 DEBUG [org.keycloak.authentication.DefaultAuthenticationFlow] (default task-75) check execution: 'auth-cookie', requirement: 'ALTERNATIVE' 2020-04-10 11:26:20,770 DEBUG [org.keycloak.authentication.DefaultAuthenticationFlow] (default task-75) authenticator: auth-cookie 2020-04-10 11:26:20,770 DEBUG [org.keycloak.authentication.AuthenticationSelectionResolver] (default task-75) Going through the flow 'browser' for adding executions 2020-04-10 11:26:20,770 DEBUG [org.keycloak.authentication.AuthenticationSelectionResolver] (default task-75) Going through the flow 'forms' for adding executions 2020-04-10 11:26:20,771 DEBUG [org.keycloak.authentication.AuthenticationSelectionResolver] (default task-75) Selections when trying execution 'auth-cookie' : [ authSelection

2020-04-10 11:26:21,067 DEBUG [io.undertow.request] (default I/O-1) Matched default handler path /realms/master/protocol/openid-connect/token/introspect 2020-04-10 11:26:21,068 DEBUG [io.undertow.request] (default I/O-1) UT005013: An IOException occurred: java.nio.channels.ClosedChannelException at io.undertow.protocols.ssl.SslConduit.doWrap(SslConduit.java:876) at io.undertow.protocols.ssl.SslConduit.doHandshake(SslConduit.java:649) at io.undertow.protocols.ssl.SslConduit.access$900(SslConduit.java:63) at io.undertow.protocols.ssl.SslConduit$SslReadReadyHandler.readReady(SslConduit.java:1137) at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:89) at org.xnio.nio.WorkerThread.run(WorkerThread.java:591)`

But in odoo log I have this :

2020-04-10 09:26:20,826 9858 INFO sso werkzeug: 192.168.20.11 - - [10/Apr/2020 09:26:20] "GET /auth_oauth/signin HTTP/1.1" 200 - 2020-04-10 09:26:21,072 9858 ERROR sso odoo.addons.auth_oauth.controllers.main: OAuth2: Not Found Traceback (most recent call last): File "/opt/odoo/odoo11/addons/auth_oauth/controllers/main.py", line 133, in signin credentials = env['res.users'].sudo().auth_oauth(provider, kw) File "/opt/odoo/odoo11/addons/auth_oauth/models/res_users.py", line 96, in auth_oauth validation = self._auth_oauth_validate(provider, access_token) File "/opt/odoo/odoo11-custom-addons/auth_keycloak/models/res_users.py", line 44, in _auth_oauth_validate validation = self._keycloak_validate(oauth_provider, access_token) File "/opt/odoo/odoo11-custom-addons/auth_keycloak/models/res_users.py", line 28, in _keycloak_validate raise OAuthError(resp.reason) odoo.addons.auth_keycloak.exceptions.OAuthError: Not Found 2020-04-10 09:26:21,075 9858 INFO sso werkzeug: 192.168.20.11 - - [10/Apr/2020 09:26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Cg&token_type=bearer&expires_in=900 HTTP/1.1" 303 - 2020-04-10 09:26:21,150 9858 INFO sso werkzeug: 192.168.20.11 - - [10/Apr/2020 09:26:21] "GET /web/login?oauth_error=2 HTTP/1.1" 200 -

The documentation doesn't explain how to configure Keycloak, but I think the problem is on the Odoo side.

Thank you for your help !

Regards,

Nicolas

NicolasDEVOUGE commented 4 years ago

I precise that the exaple test with the c2c user is good, I have a token, and can test that is working

janikvonrotz commented 4 years ago

To make it work you need a few changes. Have a look here:

https://janikvonrotz.ch/2020/04/24/odoo-oauth-authentication-with-keycloak/

assign101 commented 2 years ago

I followed your instructions but getting a invalid_token and access denied..

Traceback (most recent call last): File "/opt/bitnami/odoo/lib/odoo-14.0.post20211010-py3.8.egg/odoo/addons/auth_oauth/controllers/main.py", line 133, in signin credentials = env['res.users'].sudo().auth_oauth(provider, kw) File "/opt/bitnami/odoo/lib/odoo-14.0.post20211010-py3.8.egg/odoo/addons/auth_oauth/models/res_users.py", line 96, in auth_oauth validation = self._auth_oauth_validate(provider, access_token) File "/bitnami/odoo/addons/auth_oauth_keycloak/models/res_users.py", line 41, in _auth_oauth_validate raise Exception(validation['error']) Exception: invalid_token

image

Any help much appreciated.

deepa4lok commented 2 years ago

In Odoo Configuration, change the scope to 'profile'. that should work

github-actions[bot] commented 1 year ago

There hasn't been any activity on this issue in the past 6 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. If you want this issue to never become stale, please ask a PSC member to apply the "no stale" label.