-
Notifications
You must be signed in to change notification settings - Fork 451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
migrate oauth2 into upstream #1689
Merged
+93
−5
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
30389f4
initial from https://gitlab.mim-libre.fr/alphabet/radicale_oauth/-/bl…
pbiering 0638837
add copyright
pbiering 937acf3
oauth2 config check improvement
pbiering e28b719
oauth2 example config
pbiering 87dc553
oauth2 module enabling
pbiering 23a68b2
extend mypy options
pbiering 04523e5
oauth2 config option
pbiering 7b61464
make tox happy
pbiering d2be086
oauth2 adjustments to radicale changes in the past
pbiering e0d20ed
oauth2 do not throw exception in case server is not reachable
pbiering cfcfbbd
oauth2 changelog
pbiering f3a7641
3.4.2.dev
pbiering 6f68a64
oauth2 doc
pbiering File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ name = "Radicale" | |
# When the version is updated, a new section in the CHANGELOG.md file must be | ||
# added too. | ||
readme = "README.md" | ||
version = "3.4.1" | ||
version = "3.4.2.dev" | ||
authors = [{name = "Guillaume Ayoub", email = "[email protected]"}, {name = "Unrud", email = "[email protected]"}, {name = "Peter Bieringer", email = "[email protected]"}] | ||
license = {text = "GNU GPL v3"} | ||
description = "CalDAV and CardDAV Server" | ||
|
@@ -72,7 +72,7 @@ skip_install = true | |
|
||
[tool.tox.env.mypy] | ||
deps = ["mypy==1.11.0"] | ||
commands = [["mypy", "."]] | ||
commands = [["mypy", "--install-types", "--non-interactive", "."]] | ||
skip_install = true | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# This file is part of Radicale Server - Calendar Server | ||
# | ||
# Original from https://gitlab.mim-libre.fr/alphabet/radicale_oauth/ | ||
# Copyright © 2021-2022 Bruno Boiget | ||
# Copyright © 2022-2022 Daniel Dehennin | ||
# | ||
# Since migration into upstream | ||
# Copyright © 2025-2025 Peter Bieringer <[email protected]> | ||
# | ||
# This library is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This library is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with Radicale. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
""" | ||
Authentication backend that checks credentials against an oauth2 server auth endpoint | ||
""" | ||
|
||
import requests | ||
|
||
from radicale import auth | ||
from radicale.log import logger | ||
|
||
|
||
class Auth(auth.BaseAuth): | ||
def __init__(self, configuration): | ||
super().__init__(configuration) | ||
self._endpoint = configuration.get("auth", "oauth2_token_endpoint") | ||
if not self._endpoint: | ||
logger.error("auth.oauth2_token_endpoint URL missing") | ||
raise RuntimeError("OAuth2 token endpoint URL is required") | ||
logger.info("auth OAuth2 token endpoint: %s" % (self._endpoint)) | ||
|
||
def _login(self, login, password): | ||
"""Validate credentials. | ||
Sends login credentials to oauth token endpoint and checks that a token is returned | ||
""" | ||
try: | ||
# authenticate to authentication endpoint and return login if ok, else "" | ||
req_params = { | ||
"username": login, | ||
"password": password, | ||
"grant_type": "password", | ||
"client_id": "radicale", | ||
} | ||
req_headers = {"Content-Type": "application/x-www-form-urlencoded"} | ||
response = requests.post( | ||
self._endpoint, data=req_params, headers=req_headers | ||
) | ||
if ( | ||
response.status_code == requests.codes.ok | ||
and "access_token" in response.json() | ||
): | ||
return login | ||
except OSError as e: | ||
logger.critical("Failed to authenticate against OAuth2 server %s: %s" % (self._endpoint, e)) | ||
logger.warning("User failed to authenticate using OAuth2: %r" % login) | ||
return "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This password grant type is rarely enabled, so this is will usually not work.
Instead, the client app sends the user to an auth page in the browser, which returns an authCode, then the app uses the OAuth server to change that auth code into an access token and refresh token, and then the app passes the access token to the app server (radicale). The app server only needs to check whether the access token is valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have assumed this already, see my comments in the discussions...if one really want to have OAuth2 inside radicale and not terminating on reverse proxy in front of, further code contribution is required (incl. all the error handling).
PR(s) are welcome!