サービスと認証

□未翻訳

□翻訳中

□翻訳完了(Omi Chiba)

■レビュー(Yota Ichino)

サービスと認証

Authentication

前の章で次のようなデコレータについて説明をしました:

In the previous chapter we have discussed the use of the following decorators:

1.

2.

3.

@auth.requires_login()

@auth.requires_membership(...)

@auth.requires_permission(...)

通常のアクション(サービスとしてのデコレータではない)では、これらのデコレータをHTML以外のフォーマットにレンダリングすることもできます。

For normal actions (not decorated as services), these decorators can be used even if the output is rendered in a format other than HTML.

サービスとして定義された関数と@service... @auth...デコレータは使用されるべきではありません。異なる二つのタイプのデコレータを混在させることはできません。もし認証が実行された場合、そのcallアクションはデコレータされる必要があります。

For functions defined as services and decorated using the @service... decorators, the@auth... decorators should not be used. The two types of decorators cannot be mixed. If authentication is to be performed, it is the call actions that needs to be decorated:

1.

2.

@auth.requires_login()

def call(): return service()

複数のサービスオブジェクトをインスタンス化し、それらを同様の異なる関数に登録し、その片方を権限付きで公開するということが可能である点に注意してください。

Notice that it also possible to instantiate multiple service objects, register the same different functions with them, and expose some of them with authentication and some not:

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

14.

public_services=Service(globals())

private_services=Service(globals())

@public_service.jsonrpc

@private_service.jsonrpc

def f(): return 'public'

@private_service.jsonrpc

def g(): return 'private'

def public_call(): return public_service()

@auth.requires_login()

def private_call(): return private_service()

これは呼び出し元がHTTPヘッダー(前章で記述された有効なセッションクッキーやBasic認証を利用して)にクレデンシャルを渡すことを前提にしています。クライアントはそれをサポートしている必要があります:一部のクライアントはサポートしていません。

This assumes that the caller is passing credentials in the HTTP header (a valid session cookie or using basic authentication, as discussed in the previous section). The client must support it; not all clients do.