Esempio n. 1
0
def provide_credentials(method, handler, *args, **kwargs):
    """
    Similar to :func:`require_credentials` but instead of automatically redirecting the user when credentials are required it allows you to take your own action.

    You can use :meth:`OAuth.has_credentials()` to interrogate.
    """
    oauth = handler.components.oauth
    user_credentials = OAuth2UserCredentials.find(user=handler.user, scopes=oauth.scopes, admin=False)
    oauth._user_credentials = user_credentials
    return method(handler, *args, **kwargs)
Esempio n. 2
0
def provide_credentials(method, controller, *args, **kwargs):
    """
    Similar to :func:`require_credentials` but instead of automatically redirecting the user when credentials are required it allows you to take your own action.

    You can use :meth:`OAuth.has_credentials()` to interrogate.
    """
    oauth = controller.components.oauth
    user_credentials = OAuth2UserCredentials.find(user=controller.user,
                                                  scopes=oauth.scopes,
                                                  admin=False)
    oauth._user_credentials = user_credentials
    return method(controller, *args, **kwargs)
Esempio n. 3
0
def require_admin_credentials(method, handler, *args, **kwargs):
    """
    Requires that valid credentials exist for the administrator before executing the handler.
    Will redirect the user for authorization if the user is an admin.
    """
    oauth = handler.components.oauth
    user_credentials = OAuth2UserCredentials.find(scopes=oauth.scopes, admin=True)
    oauth._user_credentials = user_credentials
    if not oauth.has_credentials():
        return handler.redirect(oauth.authorization_url(admin=True))

    try:
        return method(handler, *args, **kwargs)
    except AccessTokenRefreshError:
        return handler.redirect(oauth.authorization_url(admin=True))
Esempio n. 4
0
def require_admin_credentials(method, controller, *args, **kwargs):
    """
    Requires that valid credentials exist for the administrator before executing the controller.
    Will redirect the user for authorization if the user is an admin.
    """
    oauth = controller.components.oauth
    user_credentials = OAuth2UserCredentials.find(scopes=oauth.scopes,
                                                  admin=True)
    oauth._user_credentials = user_credentials
    if not oauth.has_credentials():
        return controller.redirect(oauth.authorization_url(admin=True))

    try:
        return method(controller, *args, **kwargs)
    except AccessTokenRefreshError:
        return controller.redirect(oauth.authorization_url(admin=True))
Esempio n. 5
0
def require_credentials(method, handler, *args, **kwargs):
    """
    Requires that valid credentials exist for the current user before executing the handler.
    Will redirect the user for authorization.
    User handler.oauth_scopes to specify which scopes are required.
    """
    oauth = handler.components.oauth
    user_credentials = OAuth2UserCredentials.find(user=handler.user, scopes=oauth.scopes, admin=False)
    oauth._user_credentials = user_credentials
    if not oauth.has_credentials():
        return handler.redirect(oauth.authorization_url(admin=False, force_prompt=oauth.force_prompt))

    try:
        return method(handler, *args, **kwargs)
    except AccessTokenRefreshError:
        return handler.redirect(oauth.authorization_url(admin=False, force_prompt=oauth.force_prompt))
Esempio n. 6
0
def require_credentials(method, controller, *args, **kwargs):
    """
    Requires that valid credentials exist for the current user before executing the controller.
    Will redirect the user for authorization.
    User controller.oauth_scopes to specify which scopes are required.
    """
    oauth = controller.components.oauth
    user_credentials = OAuth2UserCredentials.find(user=controller.user,
                                                  scopes=oauth.scopes,
                                                  admin=False)
    oauth._user_credentials = user_credentials
    if not oauth.has_credentials():
        return controller.redirect(
            oauth.authorization_url(admin=False,
                                    force_prompt=oauth.force_prompt))

    try:
        return method(controller, *args, **kwargs)
    except AccessTokenRefreshError:
        return controller.redirect(
            oauth.authorization_url(admin=False,
                                    force_prompt=oauth.force_prompt))