-
Notifications
You must be signed in to change notification settings - Fork 32
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
fix #4106: proprietary oauth #4224
Changes from 2 commits
62f2668
572387f
ca2fffe
ccaa8f6
4980a3b
655f4de
7d2f7e0
890681e
b824893
579a421
11ab9af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
set -eou pipefail | ||
|
||
export SIREPO_FEATURE_CONFIG_PROPRIETARY_OAUTH_SIM_TYPES=flash | ||
if [[ ! ${SIREPO_SIM_OAUTH_FLASH_KEY:-} || ! ${SIREPO_SIM_OAUTH_FLASH_SECRET:-} ]]; then | ||
echo 'You must set $SIREPO_SIM_OAUTH_FLASH_KEY and $SIREPO_SIM_OAUTH_FLASH_SECRET' 1>&2 | ||
exit 1 | ||
fi | ||
sirepo service http |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,21 +90,21 @@ def api_authCompleteRegistration(self): | |
_parse_display_name(self.parse_json().get('displayName')), | ||
) | ||
return self.reply_ok() | ||
|
||
|
||
@api_perm.allow_visitor | ||
def api_authState(self): | ||
return self.reply_static_jinja( | ||
'auth-state', | ||
'js', | ||
PKDict(auth_state=_auth_state()), | ||
) | ||
|
||
|
||
@api_perm.allow_visitor | ||
def api_authLogout(self, simulation_type=None): | ||
"""Set the current user as logged out. | ||
|
||
Redirects to root simulation page. | ||
""" | ||
req = None | ||
|
@@ -135,6 +135,27 @@ def complete_registration(name=None): | |
cookie.set_value(_COOKIE_STATE, _STATE_LOGGED_IN) | ||
|
||
|
||
def control_sim_type_role(sim_type): | ||
e-carlin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
from sirepo import oauth | ||
from sirepo import auth_role_moderation | ||
|
||
t = sirepo.template.assert_sim_type(sim_type) | ||
if t not in sirepo.feature_config.auth_controlled_sim_types(): | ||
return | ||
#QUESTION(robnagler) I think this is sufficient, that is, the tests can be reversed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only thing I'm concerned about. LMK what you think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That doesn't workin in the Thoughts ccaa8f6 ? I don't love adding another api_perm and I struggled to find a name for it... |
||
if not uri_router.maybe_sim_type_required_for_api(): | ||
return | ||
u = logged_in_user() | ||
r = sirepo.auth_role.for_sim_type(t) | ||
if auth_db.UserRole.has_role(u, r) and not auth_db.UserRole.is_expired(u, r): | ||
return | ||
elif r in sirepo.auth_role.for_proprietary_oauth_sim_types(): | ||
oauth.raise_authorize_redirect(sirepo.auth_role.sim_type(role)) | ||
if r in sirepo.auth_role.for_moderated_sim_types(): | ||
auth_role_moderation.control_for_user(u, r) | ||
sirepo.util.raise_forbidden(f'uid={u} does not have access to sim_type={t}') | ||
|
||
|
||
def create_new_user(uid_generated_callback, module): | ||
import sirepo.simulation_db | ||
u = sirepo.simulation_db.user_create() | ||
|
@@ -333,47 +354,11 @@ def require_auth_basic(): | |
login(m, uid=uid) | ||
|
||
|
||
def require_sim_type(sim_type): | ||
def _assert_login(): | ||
try: | ||
return logged_in_user() | ||
except util.SRException as e: | ||
if ( | ||
getattr(e, 'sr_args', PKDict()).get('routeName') == LOGIN_ROUTE_NAME | ||
and not uri_router.is_sim_type_required_for_api() | ||
): | ||
return None | ||
raise | ||
|
||
def _moderate(uid, role): | ||
s = sirepo.auth_db.UserRoleInvite.get_status(uid, role) | ||
if s in ('clarify', 'pending'): | ||
raise sirepo.util.SRException('moderationPending', None) | ||
if s == 'denied': | ||
sirepo.util.raise_forbidden(f'uid={uid} role={role} already denied') | ||
assert s is None, \ | ||
f'Unexpected status={s} for uid={uid} and role={role}' | ||
require_email_user() | ||
raise sirepo.util.SRException('moderationRequest', None) | ||
|
||
if sim_type not in sirepo.feature_config.auth_controlled_sim_types(): | ||
return | ||
u = _assert_login() | ||
if u is None: | ||
return | ||
r = sirepo.auth_role.for_sim_type(sim_type) | ||
if auth_db.UserRole.has_role(u, r): | ||
return | ||
if r not in sirepo.auth_role.for_moderated_sim_types(): | ||
sirepo.util.raise_forbidden(f'uid={u} does not have access to sim_type={sim_type}') | ||
_moderate(u, r) | ||
|
||
|
||
def require_email_user(): | ||
uid = require_user() | ||
u = user_name(uid) | ||
i = require_user() | ||
u = user_name(i) | ||
if not pyisemail.is_email(u): | ||
util.raise_forbidden(f'uid={uid} username={u} is not an email') | ||
util.raise_forbidden(f'uid={i} username={u} is not an email') | ||
|
||
|
||
def require_user(): | ||
|
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.
Should we put a test in for why we have to pin versions? Someday we'll want to upgrade and it would be helpful to know why we pinned it in the first place