2

REST を介して Meteor コレクションの一部を公開する必要があるため、コレクション API の Meteorite パッケージを偶然見つけました。

これにより実際に REST を介して Meteor コレクションを公開できるようになりますが、セキュリティは考慮されていません。Collection API を で導入された Meteor 認証システムと統合する方法はあります0.5.2か?

4

2 に答える 2

3

はい、ちょっと。REST メテオライト パッケージを使用すると、コレクションを宣言し、コレクションで許可ルールを使用できますが、いくつかの注意事項があります (注:これは、より多くの作業を必要とする疑似コードです!)。

Players = new Meteor.Collection("players");

//a collection of associated userids and auth token headers
APIUsers = new Meteor.Collection("apiusers"); 

Players.allow({
    insert: function (userId, doc) {
        //invoking this from a RESTful context means the userId is NOT 
        //available, so you'll need to do three things things: 
        //    (1) a way to get the current http request's X-Auth-Token header
        //    (2) a collection to look up the user(s) associated with 
        //        that token
        //    (3) and an owner field on the Players collection to join back 
        //        to the found userids.
        return (_.indexOf(APIUsers.findOne(
                    {XAuthToken: __CURRENT_X_AUTH_TOKEN__}).users
                 , doc.owner) > -1;
    },
    update: function (userId, docs, fields, modifier) {
       /* similar logic */
    },
    remove: function (userId, docs) {
       /* similar logic */
    },
    fetch: ['owner']
});

しかし、RESTful アプローチはレガシー アプリケーションを Meteor コンテキストに統合するのに役立つことが証明されると思いますが、新しいプロジェクトの統合にはDDP プロトコルを検討することを強くお勧めします。

上記のように、許可ルールは GET コールバックを公開しません。これはおそらく、サーバーが公開するパブリケーションで GET が定義されていることが期待されるためです。DDP クライアントは、これらのパブリケーションをサブスクライブするために下位レベルで配線されているため、このコンテキストでの GET は RESTful アプローチよりもはるかにきめ細かくなります。

于 2012-12-06T03:46:10.487 に答える
1

これに出くわした人のために、Restivusを使用すると、コレクションで REST エンドポイントを生成し、それらのエンドポイントでユーザー認証とロールのアクセス許可を構成できます。デフォルトの認証では、Meteor の組み込みのログイン トークン メカニズムを使用して認証し、認証されたエンドポイントへのMeteor.userアクセスを提供します。デフォルトでは多すぎる、または不十分な場合は、カスタム認証方法を提供することもできます。簡単な例を次に示します (CoffeeScript を読んでいただければ幸いです)。this.userthis.userId

# Generates: GET, POST on /api/users and GET, DELETE on /api/users/:id for
# Meteor.users collection
Restivus.addCollection Meteor.users
  excludedEndpoints: ['deleteAll', 'put']
  routeOptions:
    authRequired: true
  endpoints:
    post:
      authRequired: false
    delete:
      roleRequired: 'admin'
于 2015-02-20T04:45:34.933 に答える