accesstoken2

package
v0.0.0-...-da06bfb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 18 Imported by: 2

Documentation

Index

Constants

View Source
const (
	Version       = "007"
	VersionLength = 3

	// Service type
	ServiceTypeRtc       = 1
	ServiceTypeRtm       = 2
	ServiceTypeStreaming = 3
	ServiceTypeFpa       = 4
	ServiceTypeChat      = 5
	ServiceTypeFCdn      = 6
	ServiceTypeApaas     = 7
	ServiceTypeRtm2      = 8

	// Rtc
	PrivilegeJoinChannel        = 1
	PrivilegePublishAudioStream = 2
	PrivilegePublishVideoStream = 3
	PrivilegePublishDataStream  = 4

	// Rtm
	// Fpa
	PrivilegeLogin = 1

	// Streaming
	PrivilegeStreamingPublishMixStream = 1
	PrivilegeStreamingPublishRawStream = 2

	// FCDN
	PrivilegeFCdnPublish = 1
	PrivilegeFCdnPlay    = 2

	// Chat
	PrivilegeChatUser = 1
	PrivilegeChatApp  = 2

	// Apaas
	PrivilegeApaasRoomUser = 1
	PrivilegeApaasUser     = 2
	PrivilegeApaasApp      = 3

	// RTM2 resource types
	Rtm2ResourceMessageChannels = 0
	Rtm2ResourceStreamChannels  = 1
	Rtm2ResourceGroupChannels   = 2
	Rtm2ResourceServerGroups    = 3
	Rtm2ResourceUsers           = 4

	// RTM2 permission types
	Rtm2PermissionRead  = 0
	Rtm2PermissionWrite = 1
)

Variables

This section is empty.

Functions

func AssertEqual

func AssertEqual(t *testing.T, expected, actual interface{})

AssertEqual reports a value mismatch and its caller location.

func AssertNil

func AssertNil(t *testing.T, err error)

AssertNil reports a non-nil, non-EOF error and its caller location.

func GetUidStr

func GetUidStr(uid uint32) string

GetUidStr converts a numeric user ID to its token representation.

func Md5

func Md5(str string) string

Md5 returns the lowercase hexadecimal MD5 digest of a string.

Types

type AccessToken

type AccessToken struct {
	AppCert string
	AppId   string
	Expire  uint32
	IssueTs uint32
	Salt    uint32

	Services []IService
	// contains filtered or unexported fields
}

func CreateAccessToken

func CreateAccessToken() (accessToken *AccessToken)

CreateAccessToken creates an empty access token for parsing.

func NewAccessToken

func NewAccessToken(appId string, appCert string, expire uint32) (accessToken *AccessToken)

NewAccessToken creates an access token with the current timestamp and a random salt.

func (*AccessToken) AddService

func (accessToken *AccessToken) AddService(service IService)

AddService adds a service without replacing an existing service of the same type.

func (*AccessToken) Build

func (accessToken *AccessToken) Build() (res string, err error)

Build serializes all services into a Token007 token and requires at least one service.

func (*AccessToken) GetServices

func (accessToken *AccessToken) GetServices(serviceType uint16) []IService

GetServices returns all services of the requested type in insertion or token order.

func (*AccessToken) Parse

func (accessToken *AccessToken) Parse(token string) (res bool, err error)

Parse parses known services and keeps the original signing bytes for independent verification.

func (*AccessToken) VerifySignature

func (accessToken *AccessToken) VerifySignature(appCertificate string) (bool, error)

VerifySignature verifies the parsed token without rebuilding its service payload.

type IService

type IService interface {
	Pack(io.Writer) error
	UnPack(io.Reader) error
	// contains filtered or unexported methods
}

type Rtm2Permissions

type Rtm2Permissions struct {
	Details map[uint16]map[uint16][]string
}

func NewRtm2Permissions

func NewRtm2Permissions() *Rtm2Permissions

NewRtm2Permissions creates an empty RTM2 permission set.

func (*Rtm2Permissions) Add

func (permissions *Rtm2Permissions) Add(resourceType uint16, permissionType uint16, resources []string)

Add adds or replaces resources for an RTM2 resource and permission type.

type Service

type Service struct {
	Privileges map[uint16]uint32
	Type       uint16
}

func NewService

func NewService(serviceType uint16) (service *Service)

NewService creates a service with the specified type and an empty privilege map.

func (*Service) AddPrivilege

func (service *Service) AddPrivilege(privilege uint16, expire uint32)

AddPrivilege sets the expiration time for a service privilege.

func (*Service) Pack

func (service *Service) Pack(w io.Writer) (err error)

Pack writes the service type and privileges.

func (*Service) UnPack

func (service *Service) UnPack(r io.Reader) (err error)

UnPack reads the service privileges after the type has been consumed.

type ServiceApaas

type ServiceApaas struct {
	*Service
	RoomUuid string
	UserUuid string
	Role     int16
}

func NewServiceApaas

func NewServiceApaas(roomUuid string, userUuid string, role int16) (serviceApaas *ServiceApaas)

NewServiceApaas creates an APaaS service for a room, user, and role.

func (*ServiceApaas) Pack

func (serviceApaas *ServiceApaas) Pack(w io.Writer) (err error)

Pack writes the APaaS service, room, user, and role.

func (*ServiceApaas) UnPack

func (serviceApaas *ServiceApaas) UnPack(r io.Reader) (err error)

UnPack reads the APaaS privileges, room, user, and role.

type ServiceChat

type ServiceChat struct {
	*Service
	UserId string
}

func NewServiceChat

func NewServiceChat(userId string) (serviceChat *ServiceChat)

NewServiceChat creates a Chat service for a user ID.

func (*ServiceChat) Pack

func (serviceChat *ServiceChat) Pack(w io.Writer) (err error)

Pack writes the Chat service and user ID.

func (*ServiceChat) UnPack

func (serviceChat *ServiceChat) UnPack(r io.Reader) (err error)

UnPack reads the Chat privileges and user ID.

type ServiceFCdn

type ServiceFCdn struct {
	*Service
	ChannelName string
	Account     string
}

func NewServiceFCdn

func NewServiceFCdn(channelName string, account string) *ServiceFCdn

NewServiceFCdn creates an FCDN service for a channel and user account.

func NewServiceFCdnWithUid

func NewServiceFCdnWithUid(channelName string, uid uint32) *ServiceFCdn

NewServiceFCdnWithUid creates an FCDN service with a numeric user ID.

func (*ServiceFCdn) Pack

func (serviceFCdn *ServiceFCdn) Pack(w io.Writer) (err error)

Pack writes the FCDN service, channel name, and user account.

func (*ServiceFCdn) UnPack

func (serviceFCdn *ServiceFCdn) UnPack(r io.Reader) (err error)

UnPack reads the FCDN privileges, channel name, and user account.

type ServiceFpa

type ServiceFpa struct {
	*Service
}

func NewServiceFpa

func NewServiceFpa() (serviceFpa *ServiceFpa)

NewServiceFpa creates an FPA service.

func (*ServiceFpa) Pack

func (serviceFpa *ServiceFpa) Pack(w io.Writer) (err error)

Pack writes the FPA service and privileges.

func (*ServiceFpa) UnPack

func (serviceFpa *ServiceFpa) UnPack(r io.Reader) (err error)

UnPack reads the FPA privileges.

type ServiceRtc

type ServiceRtc struct {
	*Service
	ChannelName string
	Uid         string
}

func NewServiceRtc

func NewServiceRtc(channelName string, uid string) (serviceRtc *ServiceRtc)

NewServiceRtc creates an RTC service for a channel and user ID.

func (*ServiceRtc) Pack

func (serviceRtc *ServiceRtc) Pack(w io.Writer) (err error)

Pack writes the RTC service, channel name, and user ID.

func (*ServiceRtc) UnPack

func (serviceRtc *ServiceRtc) UnPack(r io.Reader) (err error)

UnPack reads the RTC privileges, channel name, and user ID.

type ServiceRtm

type ServiceRtm struct {
	*Service
	UserId string
}

func NewServiceRtm

func NewServiceRtm(userId string) (serviceRtm *ServiceRtm)

NewServiceRtm creates an RTM service for a user ID.

func (*ServiceRtm) Pack

func (serviceRtm *ServiceRtm) Pack(w io.Writer) (err error)

Pack writes the RTM service and user ID.

func (*ServiceRtm) UnPack

func (serviceRtm *ServiceRtm) UnPack(r io.Reader) (err error)

UnPack reads the RTM privileges and user ID.

type ServiceRtm2

type ServiceRtm2 struct {
	*Service
	UserId      string
	Permissions *Rtm2Permissions
}

func NewServiceRtm2

func NewServiceRtm2(userId string, permissions *Rtm2Permissions) *ServiceRtm2

NewServiceRtm2 creates an RTM2 service with resource-level permissions.

func (*ServiceRtm2) Pack

func (serviceRtm2 *ServiceRtm2) Pack(w io.Writer) (err error)

Pack writes the RTM2 service, user ID, and resource permissions.

func (*ServiceRtm2) UnPack

func (serviceRtm2 *ServiceRtm2) UnPack(r io.Reader) (err error)

UnPack reads the RTM2 privileges, user ID, and resource permissions.

type ServiceStreaming

type ServiceStreaming struct {
	*Service
	ChannelName string
	Account     string
}

func NewServiceStreaming

func NewServiceStreaming(channelName string, account string) *ServiceStreaming

NewServiceStreaming creates a Streaming service for a channel and user account.

func NewServiceStreamingWithUid

func NewServiceStreamingWithUid(channelName string, uid uint32) *ServiceStreaming

NewServiceStreamingWithUid creates a Streaming service with a numeric user ID.

func (*ServiceStreaming) Pack

func (serviceStreaming *ServiceStreaming) Pack(w io.Writer) (err error)

Pack writes the Streaming service, channel name, and user account.

func (*ServiceStreaming) UnPack

func (serviceStreaming *ServiceStreaming) UnPack(r io.Reader) (err error)

UnPack reads the Streaming privileges, channel name, and user account.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL