Skip to content
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

[WIP] OpenID connect client library - eyeing toward deploying keycloak #299

Open
wants to merge 26 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9d528f7
OpenID connect client library - eyeing toward deploying keycloak
ntai-arxiv Jul 26, 2024
4765e51
Work dump
ntai-arxiv Aug 6, 2024
c1d4037
Add JWT token making interface
ntai-arxiv Aug 6, 2024
7ccb479
User claim dictionary slightly smaller. Apprently, nginx default head…
ntai-arxiv Aug 9, 2024
0a76ef3
Redo - simplify
ntai-arxiv Aug 9, 2024
e4d4bfd
Update Role names - less cryptic.
ntai-arxiv Aug 9, 2024
03df0e9
Add client secret support.
ntai-arxiv Aug 11, 2024
5b6c747
logout URL is no longer a proprety, it's now a function and you can p…
ntai-arxiv Aug 20, 2024
de6dbcd
oops.
ntai-arxiv Aug 20, 2024
1f0b695
naming is hard.
ntai-arxiv Aug 20, 2024
ecfc74c
Redo the oidc and user claims - make cookie/claims smaller.
ntai-arxiv Aug 21, 2024
4934e21
:(
ntai-arxiv Aug 21, 2024
49a18a8
Start of bridging the oauth2 cookie to legacy.
ntai-arxiv Aug 21, 2024
cc0597a
some progerss made.
ntai-arxiv Aug 23, 2024
2ee7f64
1 - Add "aud" checking to pass for oidc_idp.py
ntai-arxiv Aug 27, 2024
190a236
Ues all but "aud" token verity.
ntai-arxiv Aug 30, 2024
f23b810
Support refreshing access token. The claims now includes the refresh …
ntai-arxiv Sep 3, 2024
ca287e1
" " space was a bad choice for the delimiter.
ntai-arxiv Sep 4, 2024
4c6b9ac
Finish off implementing the token refresh. The refresh is untested fo…
ntai-arxiv Sep 6, 2024
80f658c
Nit fix, and use user_id rather than email for setting up Tapir. user…
ntai-arxiv Sep 13, 2024
44ed197
Merge branch 'develop' into ntai/openid-connect-step-1
ntai-arxiv Sep 13, 2024
df06d5a
Remove the "transaction" thing. It broke. Also fix a stupidity.
ntai-arxiv Sep 13, 2024
bfb93c6
Change the token format and make it future proof by a version prefix.
ntai-arxiv Sep 17, 2024
a86117c
Include the token expiration timestamp in the return value of encode_…
ntai-arxiv Sep 23, 2024
1ca5c01
refresh token, the function now only need the refresh token only rath…
ntai-arxiv Sep 23, 2024
683177a
Try not using access token (usu payload) instead for the user claims.…
ntai-arxiv Sep 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,5 @@ dist/

fastly_hourly_stats.ini

test.db-journal
foo.json
test.db-journal
33 changes: 33 additions & 0 deletions arxiv/auth/auth_bridge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from . import domain
from .legacy.util import _compute_capabilities
from .user_claims import ArxivUserClaims
from .legacy.authenticate import instantiate_tapir_user, _get_user_by_user_id
from ..db import transaction
from .legacy.sessions import create as legacy_create_session
from .legacy.cookies import pack as legacy_pack

def populate_user_claims(user_claims: ArxivUserClaims):
"""
Populate the user's claims to the universe
"""
with transaction():
passdata = _get_user_by_user_id(user_claims.user_id)
d_user, d_auth = instantiate_tapir_user(passdata)

session: domain.Session = legacy_create_session(d_auth, user=d_user,
tracking_cookie=user_claims.session_id)
user_claims.update_claims('tapir_session_id', session.session_id)


def bake_cookies(user_claims: ArxivUserClaims) -> (str, str):

cit_cookie = legacy_pack(user_claims.tapir_session_id,
issued_at=user_claims.issued_at,
user_id=user_claims.user_id,
capabilities=_compute_capabilities(
user_claims.is_admin,
user_claims.email_verified,
user_claims.is_god
))

return cit_cookie, ArxivUserClaims.to_arxiv_token_string
23 changes: 23 additions & 0 deletions arxiv/auth/legacy/authenticate.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,29 @@ def authenticate(username_or_email: Optional[str] = None,
except Exception as ex:
raise AuthenticationFailed() from ex

return instantiate_tapir_user(passdata)


def instantiate_tapir_user(passdata: PassData) -> Tuple[domain.User, domain.Authorizations]:
"""
Make Tapir user data from pass-data

Parameters
----------
passdata : PassData

Returns
-------
:class:`domain.User`
:class:`domain.Authorizations`

Raises
------
:class:`AuthenticationFailed`
Failed to authenticate user with provided credentials.
:class:`Unavailable`
Unable to connect to DB.
"""
db_user, _, db_nick, db_profile = passdata
user = domain.User(
user_id=str(db_user.user_id),
Expand Down
10 changes: 7 additions & 3 deletions arxiv/auth/legacy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ def drop_all(engine: Engine) -> None:

def compute_capabilities(tapir_user: TapirUser) -> int:
"""Calculate the privilege level code for a user."""
return int(sum([2 * tapir_user.flag_edit_users,
4 * tapir_user.flag_email_verified,
8 * tapir_user.flag_edit_system]))
return _compute_capabilities(tapir_user.flag_edit_users,
tapir_user.flag_email_verified,
tapir_user.flag_edit_system)

def _compute_capabilities(is_admin: int | bool, email_verified: int | bool, is_god: int | bool) -> int:
"""Calculate the privilege level code for a user."""
return int(sum([2 if is_admin else 0, 4 if email_verified else 0, 8 if is_god else 0]))


def get_scopes(db_user: TapirUser) -> List[domain.Scope]:
Expand Down
Empty file added arxiv/auth/openid/__init__.py
Empty file.
Loading
Loading