Exemple #1
0
def check_session_oauth2_token(autorenew=True, user=None):
    from app.modules.auth.models import OAuth2Token

    if user is None:
        user = current_user

    if not user.is_authenticated:
        return False

    session_oauth2_access_token = session.get('access_token', None)
    if session_oauth2_access_token is None:
        return False

    session_oauth2_bearer_token = OAuth2Token.find(
        access_token=session_oauth2_access_token)
    if session_oauth2_bearer_token is None:
        if autorenew:
            create_session_oauth2_token()
            return True
        else:
            return False

    if session_oauth2_bearer_token.is_expired:
        if autorenew:
            create_session_oauth2_token()
            return True
        else:
            return False

    return None
Exemple #2
0
def delete_session_oauth2_token(user=None):
    from app.modules.auth.models import OAuth2Token

    if user is None:
        user = current_user

    session_oauth2_access_token = session.get('access_token', None)
    if session_oauth2_access_token is not None:
        session_oauth2_bearer_token = OAuth2Token.find(
            access_token=session_oauth2_access_token)
        log.info(
            'Deleting bearer token %r for user %r' %
            (session_oauth2_bearer_token, user.email), )
        if session_oauth2_bearer_token is not None:
            session_oauth2_bearer_token.delete()