Merge pull request #1997 from magicbrothers/1996-oauth2-allow-custom-client-id-and-client-secret
[OAuth2] Allow custom client_id and client_secret
This commit is contained in:
@@ -1360,6 +1360,22 @@ Endpoint URL for the OAuth2 token
|
|||||||
|
|
||||||
Default: (unset)
|
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
|
##### pam_service
|
||||||
|
|
||||||
_(>= 3.5.0)_
|
_(>= 3.5.0)_
|
||||||
|
|||||||
6
config
6
config
@@ -156,6 +156,12 @@
|
|||||||
# OAuth2 token endpoint URL
|
# OAuth2 token endpoint URL
|
||||||
#oauth2_token_endpoint = <URL>
|
#oauth2_token_endpoint = <URL>
|
||||||
|
|
||||||
|
# OAuth2 client id
|
||||||
|
#oauth2_client_id = radicale
|
||||||
|
|
||||||
|
# OAuth2 client secret (optional)
|
||||||
|
#oauth2_client_secret =
|
||||||
|
|
||||||
# PAM service
|
# PAM service
|
||||||
#pam_serivce = radicale
|
#pam_serivce = radicale
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ class Auth(auth.BaseAuth):
|
|||||||
def __init__(self, configuration):
|
def __init__(self, configuration):
|
||||||
super().__init__(configuration)
|
super().__init__(configuration)
|
||||||
self._endpoint = configuration.get("auth", "oauth2_token_endpoint")
|
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:
|
if not self._endpoint:
|
||||||
logger.error("auth.oauth2_token_endpoint URL missing")
|
logger.error("auth.oauth2_token_endpoint URL missing")
|
||||||
raise RuntimeError("OAuth2 token endpoint URL is required")
|
raise RuntimeError("OAuth2 token endpoint URL is required")
|
||||||
@@ -49,8 +51,11 @@ class Auth(auth.BaseAuth):
|
|||||||
"username": login,
|
"username": login,
|
||||||
"password": password,
|
"password": password,
|
||||||
"grant_type": "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"}
|
req_headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
self._endpoint, data=req_params, headers=req_headers
|
self._endpoint, data=req_params, headers=req_headers
|
||||||
|
|||||||
@@ -354,6 +354,14 @@ DEFAULT_CONFIG_SCHEMA: types.CONFIG_SCHEMA = OrderedDict([
|
|||||||
"value": "",
|
"value": "",
|
||||||
"help": "OAuth2 token endpoint URL",
|
"help": "OAuth2 token endpoint URL",
|
||||||
"type": str}),
|
"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", {
|
("pam_group_membership", {
|
||||||
"value": "",
|
"value": "",
|
||||||
"help": "PAM group user should be member of",
|
"help": "PAM group user should be member of",
|
||||||
|
|||||||
Reference in New Issue
Block a user