Seafile OAuth2 Problem with Keycloak

Hi,

i am testing the sso login for seafile docker container over oauth2 with keycloak as auth provider.

When i click SSO on the login page i will be redirected to the keycloak login site.
After Login i will be redirected to the callback site of seafile an only become the message “Error, please contact Administrator”

i test several things, but didnt find the problem.
in the seahub.log there are nothing about a oauth problem.
maybe i must activate some debugging switches which i dont know.

i think the problem is the user creation with the infos from the keycloak userinfo url

The current config is the following:

ENABLE_SIGNUP = True
ACTIVATE_AFTER_REGISTRATION = True
ENABLE_OAUTH = True

OAUTH_CLIENT_ID = “%app-id%”
OAUTH_CLIENT_SECRET = “%secret%”

OAUTH_REDIRECT_URL =‘https://%seafile-url%/oauth/callback’

OAUTH_PROVIDER_DOMAIN = “%domain-of-the-seafile-url%”
OAUTH_AUTHORIZATION_URL = ‘https://%keycloakurl%/auth/realms/%realmname%/protocol/openid-connect/auth’
OAUTH_TOKEN_URL = ‘https://%keycloakurl%/auth/realms/%realmname%/protocol/openid-connect/token’
OAUTH_USER_INFO_URL = ‘https://%keycloakurl%/auth/realms/%realmname%/protocol/openid-connect/userinfo’
OAUTH_SCOPE = [’%client-scope-name%’]
OAUTH_ATTRIBUTE_MAP = {
“email”: (True, “email”),
“id”: (False, “sub”),
“name”: (False, “name”)
}

When i test the userinfo url with oauth2 authentication i receive the correct attributes with the correct values which i use in the oauth config.

Hope someone can help me in this topic.

Thanks

Hi rlo,

I see two possibilities why the sso login can fail:

  1. oauth settings are wrong
    often there is an error in the oauth_attribute_map. We already had a similar forum entry here. Maybe this will help:
    OAuth question - error with SSO

  2. user can not be created automatically
    ich hatte in der vergangenheit den fall, dass so ein fehler nicht an einem fehlerhaften sso lag sondern an der tatsache, dass in der seahub settings einstellungen festgelegt waren, die eine benutzeranlage verhindern haben:

  • ACTIVATE_AFTER_REGISTRATION
  • ENABLE_SIGNUP = False

I wish you success
Christoph

Hey rlo,

I don’t know If your problem is already solved but I wrote a short blog post how to setup seafile with keycloak. The article is in German but probably it will help you.

Best regards
Christoph

Hi Christoph,

vielen Dank für die ausführliche Anleitung. Die Anbindung an Keycloak war tatsächlich in 10 min erledigt.
Eine Frage: Ich hätte gerne, dass das Seafile-Login gar nicht mehr erscheint, sondern direkt zu Keycloak umgeleitet wird. Gibt es dafür einen Parameter?

Danke, Gruß Andreas

Hallo Andreas,
soweit ich weiß geht das nicht. Keycloak muss ja auch wissen, wohin es zurück springen soll. Das geht nicht, wenn du einfach nur die Login-Seite von Keycloak direkt aufrufst.
Gruß
Christoph

Seafile könnte aber schon statt der Login-Seite direkt umleiten.

technisch geht es schon. Bei OpenProject ist es so umgesetzt. Die Einstiegsseite von OP leitet auf Keycloak um und gibt die ClientID und das Secret mit, dadurch weiss Keycloak, wohin weitergeleitet werden muss.

Hi, is it possible to setup keycloak to an existing seafile instance? For understand we already have seafile for a while. Now I setup Keycloak to unify whole company employees authentication. But I don’t know how to pair users from keycloak(new, can be deleted) to seafile(already created, with libraries - cannot be deleted).

Any hit for this?