Skip to content

Instantly share code, notes, and snippets.

@Xarthisius
Last active April 1, 2020 22:57
Show Gist options
  • Save Xarthisius/25b7c271b438ee5332be2c7618f94b3c to your computer and use it in GitHub Desktop.
Save Xarthisius/25b7c271b438ee5332be2c7618f94b3c to your computer and use it in GitHub Desktop.
[girder] Enforcing admin approval for OAuth
from girder.exceptions import AccessException
from girder.models.user import User
from girder import events
def enforce_policy(event):
user = event.info["user"]
# This has the same behavior as User.canLogin, but returns more
# detailed error messages
if user.get("status", "enabled") == "disabled":
raise AccessException("Account is disabled.", extra="disabled")
if User().emailVerificationRequired(user):
raise AccessException("Email verification required.", extra="emailVerification")
if User().adminApprovalRequired(user):
raise AccessException("Account approval required.", extra="accountApproval")
def load(info):
events.bind("oauth.auth_callback.after", "your_plugin_name", enforce_policy)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment