diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 858bb944..43bba942 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -1360,6 +1360,22 @@ Endpoint URL for the OAuth2 token Default: (unset) +##### oauth2_client_id + +_(>= 3.7.0)_ + +Client ID used to request the Auth2 token + +Default: `radicale` + +##### oauth2_client_secret + +_(>= 3.7.0)_ + +Client secret used to request the Auth2 token + +Default: (unset) + ##### pam_service _(>= 3.5.0)_ diff --git a/config b/config index 0c5b90a6..18e29a1f 100644 --- a/config +++ b/config @@ -156,6 +156,12 @@ # OAuth2 token endpoint URL #oauth2_token_endpoint = +# OAuth2 client id +#oauth2_client_id = radicale + +# OAuth2 client secret (optional) +#oauth2_client_secret = + # PAM service #pam_serivce = radicale diff --git a/radicale/auth/oauth2.py b/radicale/auth/oauth2.py index 838a786e..87592d0b 100644 --- a/radicale/auth/oauth2.py +++ b/radicale/auth/oauth2.py @@ -34,6 +34,8 @@ class Auth(auth.BaseAuth): def __init__(self, configuration): super().__init__(configuration) self._endpoint = configuration.get("auth", "oauth2_token_endpoint") + self._client_id = configuration.get("auth", "oauth2_client_id") + self._client_secret = configuration.get("auth", "oauth2_client_secret") if not self._endpoint: logger.error("auth.oauth2_token_endpoint URL missing") raise RuntimeError("OAuth2 token endpoint URL is required") @@ -49,8 +51,11 @@ class Auth(auth.BaseAuth): "username": login, "password": password, "grant_type": "password", - "client_id": "radicale", + "client_id": self._client_id, } + if self._client_secret: + req_params["client_secret"] = self._client_secret + req_headers = {"Content-Type": "application/x-www-form-urlencoded"} response = requests.post( self._endpoint, data=req_params, headers=req_headers diff --git a/radicale/config.py b/radicale/config.py index bdca5526..6cc0460d 100644 --- a/radicale/config.py +++ b/radicale/config.py @@ -354,6 +354,14 @@ DEFAULT_CONFIG_SCHEMA: types.CONFIG_SCHEMA = OrderedDict([ "value": "", "help": "OAuth2 token endpoint URL", "type": str}), + ("oauth2_client_id", { + "value": "radicale", + "help": "OAuth2 client id", + "type": str}), + ("oauth2_client_secret", { + "value": "", + "help": "OAuth2 client secret", + "type": str}), ("pam_group_membership", { "value": "", "help": "PAM group user should be member of",