-
Notifications
You must be signed in to change notification settings - Fork 828
/
RtmTokenBuilder.go
35 lines (30 loc) · 1.16 KB
/
RtmTokenBuilder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package rtmtokenbuilder
import (
"accesstoken"
)
// Role Type
type Role uint16
// Role consts
const (
RoleRtmUser = 1
)
//RtmTokenBuilder class
type RtmTokenBuilder struct {
}
//BuildToken method
// appID: The App ID issued to you by Agora. Apply for a new App ID from
// Agora Dashboard if it is missing from your kit. See Get an App ID.
// appCertificate: Certificate of the application that you registered in
// the Agora Dashboard. See Get an App Certificate.
// userAccount: The user account.
// role: Role_Rtm_User = 1
// privilegeExpireTs: represented by the number of seconds elapsed since
// 1/1/1970. If, for example, you want to access the
// Agora Service within 10 minutes after the token is
// generated, set expireTimestamp as the current
// timestamp + 600 (seconds)./
func BuildToken(appID string, appCertificate string, userAccount string, role Role, privilegeExpiredTs uint32) (string, error) {
token := accesstoken.CreateAccessToken2(appID, appCertificate, userAccount, "")
token.AddPrivilege(accesstoken.KLoginRtm, privilegeExpiredTs)
return token.Build()
}