本文帮助需要从老版 SDK 升级高版本的用户升级到最新的动态密钥 Token。
2.1.0 版本之前,每一个鉴权服务都需要一个独立的密钥(key)。比如:
joinChannel
需要 channel key
setClientRole
需要 permission key
2.1.0 版本用一个 Token 包括了所有的服务权限信息。Token 参数仅在 joinChannel
时被传入;需要更新权限时调用 renewToken
即可。
v2.0.2 | v2.1.0 |
public int joinChannel(String channelKey, String channelName, String optionalInfo, int optionalUid); | public int joinChannel(String token, String channelName, String optionalInfo, int optionalUid); |
public int setClientRole(int role, String permissionKey) | int setClientRole(int role) |
public void onRequestChannelKey(); | public void onRequestToken(); |
public int renewChannelKey(const char* channelKey) | public int renewtoken( const char* token) |
v2.0.2 | v2.1.0 |
joinChannelByKey:channelName:info:uid:joinSuccess: | joinChannelByToken:channelId:info:uid:joinSuccess: |
setClientRole:withKey: | setClientRole: |
rtcEngineRequestChannelKey: | rtcEngineRequestToken: |
renewChannelKey: | renewToken: |
v2.0.2 | v2.1.0 |
joinChannelByKey:channelName:info:uid:joinSuccess: | joinChannelByToken:channelId:info:uid:joinSuccess: |
setClientRole:withKey: | setClientRole: |
rtcEngineRequestChannelKey: | rtcEngineRequestToken: |
renewChannelKey: | renewToken: |
v2.0.2 | v2.1.0 |
public int joinChannel(const char* channelKey, const char* channel, const char* info, uid_t uid) | public int joinChannel(String token, String channelName, String optionalInfo, int optionalUid); |
public int setClientRole(CLIENT_ROLE_TYPE role, const char* permissionKey); | int setClientRole(int role) |
public virtual void onRequestChannelKey(); | public void onRequestToken(); |
public int renewChannelKey(const char* channelKey) | public int renewtoken( const char* token) |
v2.3.1 | v2.4.0 |
client.join(channelKey, channel, uid, onSuccess, onFailure) | client.join(token, channel, uid, onSuccess, onFailure) |
client.renewChannelKey | client.renewToken |
下表比较了生成 Dynamic Key 所需字段和生成 Token 所需字段:
Dynamic Key | Token | 说明 |
App ID | App ID | |
App 证书 | App 证书 | |
channelName | channelName | |
unixTs/Ts | N/A | 删除了授权时间戳 |
uid | uid | |
expiredTs/timeputFromNow | expiredTs/timeputFromNow | 保留了服务到期时间 |
randomint/r | randomint/r | |
N/A | Role | 增加了角色及对应权限。更多详情请见:Token 的角色权限 。 |