コード例 #1
0
def index():
    """List user tokens."""
    clients = Client.query.filter_by(
        user_id=current_user.get_id(),
        is_internal=False,
    ).all()

    tokens = Token.query.options(db.joinedload('client')).filter(
        Token.user_id == current_user.get_id(),
        Token.is_personal == True,  # noqa
        Token.is_internal == False,
        Client.is_internal == True,
    ).all()

    authorized_apps = Token.query.options(db.joinedload('client')).filter(
        Token.user_id == current_user.get_id(),
        Token.is_personal == False,  # noqa
        Token.is_internal == False,
        Client.is_internal == False,
    ).all()

    return render_template(
        'invenio_oauth2server/settings/index.html',
        clients=clients,
        tokens=tokens,
        authorized_apps=authorized_apps,
    )
コード例 #2
0
 def get_by_token(cls, client_id, access_token, token_type=""):
     """Get RemoteAccount object for token."""
     return (
         cls.query.options(db.joinedload("remote_account"))
         .filter(
             RemoteAccount.id == RemoteToken.id_remote_account,
             RemoteAccount.client_id == client_id,
             RemoteToken.token_type == token_type,
             RemoteToken.access_token == access_token,
         )
         .first()
     )
コード例 #3
0
    def get(cls, user_id, client_id, token_type="", access_token=None):
        """Get RemoteToken for user."""
        args = [
            RemoteAccount.id == RemoteToken.id_remote_account,
            RemoteAccount.user_id == user_id,
            RemoteAccount.client_id == client_id,
            RemoteToken.token_type == token_type,
        ]

        if access_token:
            args.append(RemoteToken.access_token == access_token)

        return cls.query.options(db.joinedload("remote_account")).filter(*args).first()
コード例 #4
0
ファイル: models.py プロジェクト: hjhsalo/invenio-oauthclient
    def get_by_token(cls, client_id, access_token, token_type=''):
        """Get RemoteAccount object for token.

        :param client_id: The client id.
        :param access_token: The access token.
        :param token_type: The token type. (Default: ``''``)
        :returns: A :class:`invenio_oauthclient.models.RemoteToken` instance.
        """
        return cls.query.options(db.joinedload('remote_account')).filter(
            RemoteAccount.id == RemoteToken.id_remote_account,
            RemoteAccount.client_id == client_id,
            RemoteToken.token_type == token_type,
            RemoteToken.access_token == access_token,
        ).first()
コード例 #5
0
    def get_by_token(cls, client_id, access_token, token_type=''):
        """Get RemoteAccount object for token.

        :param client_id: The client id.
        :param access_token: The access token.
        :param token_type: The token type. (Default: ``''``)
        :returns: A :class:`invenio_oauthclient.models.RemoteToken` instance.
        """
        return cls.query.options(db.joinedload('remote_account')).filter(
            RemoteAccount.id == RemoteToken.id_remote_account,
            RemoteAccount.client_id == client_id,
            RemoteToken.token_type == token_type,
            RemoteToken.access_token == access_token,
        ).first()
コード例 #6
0
    def get(cls, user_id, client_id, token_type='', access_token=None):
        """Get RemoteToken for user."""
        args = [
            RemoteAccount.id == RemoteToken.id_remote_account,
            RemoteAccount.user_id == user_id,
            RemoteAccount.client_id == client_id,
            RemoteToken.token_type == token_type,
        ]

        if access_token:
            args.append(RemoteToken.access_token == access_token)

        return cls.query.options(
            db.joinedload('remote_account')).filter(*args).first()
コード例 #7
0
    def get(cls, user_id, client_id, token_type='', access_token=None):
        """Get RemoteToken for user.

        :param user_id: The user id.
        :param client_id: The client id.
        :param token_type: The token type. (Default: ``''``)
        :param access_token: If set, will filter also by access token.
            (Default: ``None``)
        :returns: A :class:`invenio_oauthclient.models.RemoteToken` instance.
        """
        args = [
            RemoteAccount.id == RemoteToken.id_remote_account,
            RemoteAccount.user_id == user_id,
            RemoteAccount.client_id == client_id,
            RemoteToken.token_type == token_type,
        ]

        if access_token:
            args.append(RemoteToken.access_token == access_token)

        return cls.query.options(
            db.joinedload('remote_account')).filter(*args).first()
コード例 #8
0
ファイル: models.py プロジェクト: hjhsalo/invenio-oauthclient
    def get(cls, user_id, client_id, token_type='', access_token=None):
        """Get RemoteToken for user.

        :param user_id: The user id.
        :param client_id: The client id.
        :param token_type: The token type. (Default: ``''``)
        :param access_token: If set, will filter also by access token.
            (Default: ``None``)
        :returns: A :class:`invenio_oauthclient.models.RemoteToken` instance.
        """
        args = [
            RemoteAccount.id == RemoteToken.id_remote_account,
            RemoteAccount.user_id == user_id,
            RemoteAccount.client_id == client_id,
            RemoteToken.token_type == token_type,
        ]

        if access_token:
            args.append(RemoteToken.access_token == access_token)

        return cls.query.options(
            db.joinedload('remote_account')
        ).filter(*args).first()
コード例 #9
0
def index():
    """List user tokens."""
    clients = Client.query.filter_by(
        user_id=current_user.get_id(),
        is_internal=False,
    ).all()

    tokens = Token.query.options(db.joinedload('client')).filter(
        Token.user_id == current_user.get_id(),
        Token.is_personal == True,  # noqa
        Token.is_internal == False,
        Client.is_internal == True,
    ).all()

    authorized_apps = Token.query.options(db.joinedload('client')).filter(
        Token.user_id == current_user.get_id(),
        Token.is_personal == False,  # noqa
        Token.is_internal == False,
        Client.is_internal == False,
    ).all()

    # scope_choices = [
    #     {
    #         "id": scope[1].id,
    #         "help_text": scope[1].help_text,
    #     } for scope in current_oauth2server.scope_choices()
    # ]

    _tokens = [
        {
            "name": t.client.name,
            "t_id": t.id,
            "scopes": t.scopes,
            "access_token": t.access_token
        } for t in tokens
    ]

    _clients = [
        {
            'client_id': c.client_id,
            'client_secret': c.client_secret,
            'client_type': c.client_type,
            'default_redirect_uri': c.default_redirect_uri,
            'default_scopes': c.default_scopes,
            'description': c.description,
            'is_confidential': c.is_confidential,
            'is_internal': c.is_internal,
            'name': c.name,
            'oauth2tokens': c.oauth2tokens,
            'redirect_uris': c.redirect_uris,
            'user_id': c.user_id,
            'website': c.website,
        }
        for c in clients
    ]

    response = {
        "clients": _clients,
        "tokens": _tokens,
        # "authorized_apps": authorized_apps,
        # "scope_choices": scope_choices,
    }

    return jsonify(response), 200