Master key support¶
Utilities for using master keys.
The master key id and secret may be obtained with the create_master_key API action. The key argument taken by all functions is a pair (e.g. a tuple) consisting of the id and the secret.
The signatures and secured metadata may be used once before the expiration time. Expiration time is specified in Unix time (seconds since 1970-01-01 UTC), and may not be more than one week in the future.
Signature generation¶
The following functions create values for the master_sign parameter of some API actions. The member_attrs argument is expected to be an iterable with pair (e.g. tuple) elements, as opposed to the API actions which expect it as a dict.
For use with the create_session action:
-
ninchat.master.
sign_create_session
(key, expire, puppet_attrs=None)¶ Use when creating a new user. The user will become a puppet of the master. The puppet_attrs specified here must be repeated in the API call.
-
ninchat.master.
sign_create_session_for_user
(key, expire, user_id)¶ Use when authenticating an existing user. The user must be a puppet of the master. The user_id specified here must be repeated in the API call.
For use with the join_channel action:
-
ninchat.master.
sign_join_channel
(key, expire, channel_id, member_attrs=None)¶ For use by any user. The master must own the channel. The channel_id and member_attrs specified here must be repeated in the API call.
-
ninchat.master.
sign_join_channel_for_user
(key, expire, channel_id, user_id, member_attrs=None)¶ For use by the specified user only. The master must own the channel. The channel_id and member_attrs specified here must be repeated in the API call.
Metadata encryption¶
The following functions create values for the “secure” property of the audience_metadata parameter of the request_audience API action. The metadata argument should be a dict or None.
(The functions are unavailable if cryptography or PyCrypto can’t be found.)
-
ninchat.master.
secure_metadata
(key, expire, metadata)¶ For use by any user.
-
ninchat.master.
secure_metadata_for_user
(key, expire, metadata, user_id)¶ For use by the specified user only.