Example #1
0
def set_token(token, request, *args, **kwargs):
    with faf.db.connection:
        # make sure that every client has only one token connected to a user
        OAuthToken.delete(request.client.client_id, current_user.id)

        expires_in = token.get('expires_in')
        expires = datetime.utcnow() + timedelta(seconds=expires_in)

        return OAuthToken.insert(
            access_token=token['access_token'],
            # TODO: Support refresh token?
            refresh_token=token.get('refresh_token', ''),
            token_type=token['token_type'],
            scope=token.scope,
            expires=expires,
            client_id=request.client.client_id,
            user_id=current_user.id)
Example #2
0
def set_token(token, request, *args, **kwargs):
    with faf.db.connection:
        # make sure that every client has only one token connected to a user
        OAuthToken.delete(request.client.client_id, current_user.id)

        expires_in = token.get('expires_in')
        expires = datetime.utcnow() + timedelta(seconds=expires_in)

        return OAuthToken.insert(
            access_token=token['access_token'],
            # TODO: Support refresh token?
            refresh_token=token.get('refresh_token', ''),
            token_type=token['token_type'],
            scope=token.scope,
            expires=expires,
            client_id=request.client.client_id,
            user_id=current_user.id
        )
Example #3
0
def set_token(token, request, *args, **kwargs):
    # https://github.com/lepture/flask-oauthlib/issues/209
    user_id = request.user.id if hasattr(request.user, 'id') else current_user.id

    # make sure that every client has only one token connected to a user
    OAuthToken.delete(request.client.client_id, user_id)

    with faf.db.connection:
        expires_in = token.get('expires_in')
        expires = datetime.utcnow() + timedelta(seconds=expires_in)

        return OAuthToken.insert(
            access_token=token['access_token'],
            # TODO: Support refresh token?
            refresh_token=token.get('refresh_token', ''),
            token_type=token['token_type'],
            scope=token.scope,
            expires=expires,
            client_id=request.client.client_id,
            user_id=user_id
        )
Example #4
0
def get_token(access_token=None, refresh_token=None):
    return OAuthToken.get(access_token=access_token, refresh_token=refresh_token)
Example #5
0
 def get_token(self, access_token=None, refresh_token=None):
     return OAuthToken(user=User(id=1),
                       client_id=1,
                       expires=datetime.datetime.now() +
                       datetime.timedelta(hours=1),
                       scopes=['write_events read_events'])
Example #6
0
def get_token(access_token=None, refresh_token=None):
    return OAuthToken.get(access_token=access_token, refresh_token=refresh_token)