Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
113f7ab
support 2.8.0
plutoless Jun 30, 2019
f184e76
Only release rtc & chat service in token007
a7vinx Dec 17, 2021
65f6754
Merge pull request #205 from a7vinx/dev/accesstoken2_release
sunshinexcode Dec 20, 2021
7328617
Remove useless token builder
a7vinx Dec 21, 2021
1486e12
Merge pull request #206 from a7vinx/dev/accesstoken2_release
sunshinexcode Dec 21, 2021
f04e21c
just support Rtc/Chat service
Dec 21, 2021
5dc593c
just support Rtc/Chat service
Dec 21, 2021
9909676
just support Rtc/Chat service
Dec 21, 2021
9580836
just support Rtc/Chat service
Dec 21, 2021
a69fc02
just support Rtc/Chat service
Dec 21, 2021
13da9ee
just support Rtc/Chat service
Dec 21, 2021
fa67e5c
just support Rtc/Chat service
Dec 21, 2021
fe46f98
new param for token life cycle control in access token 2
aldam70 Dec 29, 2021
87f5fab
support setting token and privilege expiration time
Dec 29, 2021
dcf76f7
support setting token and privilege expiration time
Dec 29, 2021
90dc846
support setting token and privilege expiration time
Dec 29, 2021
6b36c74
Merge pull request #209 from aldam70/release/token2
sunshinexcode Dec 29, 2021
4a456eb
modify comment
Dec 29, 2021
7287bfb
Merge branch 'release/accesstoken2' of https://github.com/AgoraIO/Too…
Dec 29, 2021
58d79b8
support setting token and privilege expiration time
Dec 29, 2021
0826886
modify comment
Dec 29, 2021
a1448d5
add rtc2 privilege code
oyxdsn Dec 30, 2021
bac85e0
support setting token and privilege expiration time
Dec 30, 2021
b317f95
Merge branch 'release/accesstoken2' of https://github.com/AgoraIO/Too…
Dec 30, 2021
af805b9
support setting token and privilege expiration time
Dec 30, 2021
68228ff
Merge pull request #211 from lycheng423/release/accesstoken2
sunshinexcode Dec 30, 2021
a3559db
add ut code
oyxdsn Dec 30, 2021
ca1717e
Merge pull request #1 from 2580258036Aa/golem/2.8.0
2580258036Aa Apr 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ int main(int argc, char const *argv[]) {
std::string result;
result = RtcTokenBuilder2::BuildTokenWithUid(
app_id, app_certificate, channel_name, uid, UserRole::kRolePublisher,
privilege_expiration_in_seconds);
token_expiration_in_seconds, privilege_expiration_in_seconds);
std::cout << "Token With Int Uid:" << result << std::endl;

result = RtcTokenBuilder2::BuildTokenWithUserAccount(
app_id, app_certificate, channel_name, account, UserRole::kRolePublisher,
privilege_expiration_in_seconds);
token_expiration_in_seconds, privilege_expiration_in_seconds);
std::cout << "Token With UserAccount:" << result << std::endl;

result = RtcTokenBuilder2::BuildTokenWithUid(
Expand Down
131 changes: 0 additions & 131 deletions DynamicKey/AgoraDynamicKey/cpp/src/AccessToken2.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,134 +111,6 @@ class ServiceRtc : public Service {
ServiceRtc &operator=(ServiceRtc &&) = default;
};

class ServiceRtm : public Service {
public:
enum {
kServiceType = 2,

kPrivilegeLogin = 1,
};

public:
ServiceRtm(const std::string &user_id = "")
: Service(kServiceType), user_id_(user_id) {}

virtual std::string PackService() override { return Pack(this); }

virtual void UnpackService(Unpacker *unpacker) override { *unpacker >> this; }

virtual std::unique_ptr<Service> Clone() const override {
return std::unique_ptr<Service>(new ServiceRtm(*this));
}

friend agora::tools::Packer &operator<<(agora::tools::Packer &p,
const ServiceRtm *x) {
p << dynamic_cast<const Service *>(x) << x->user_id_;
return p;
}

friend agora::tools::Unpacker &operator>>(agora::tools::Unpacker &p,
ServiceRtm *x) {
p >> dynamic_cast<Service *>(x) >> x->user_id_;
return p;
}

public:
std::string user_id_;

protected:
ServiceRtm(const ServiceRtm &) = default;
ServiceRtm(ServiceRtm &&) = default;
ServiceRtm &operator=(const ServiceRtm &) = default;
ServiceRtm &operator=(ServiceRtm &&) = default;
};

class ServiceStreaming : public Service {
public:
enum {
kServiceType = 3,

kPrivilegePublishMixStream = 1,
kPrivilegePublishRawStream = 2,
};

public:
ServiceStreaming(const std::string &channel_name = "", uint32_t uid = 0)
: Service(kServiceType), channel_name_(channel_name) {
if (uid == 0) {
account_ = "";
} else {
account_ = std::to_string(uid);
}
}

ServiceStreaming(const std::string &channel_name, const std::string &account)
: Service(kServiceType), channel_name_(channel_name), account_(account) {}

virtual std::string PackService() override { return Pack(this); }

virtual void UnpackService(Unpacker *unpacker) override { *unpacker >> this; }

virtual std::unique_ptr<Service> Clone() const override {
return std::unique_ptr<Service>(new ServiceStreaming(*this));
}

friend agora::tools::Packer &operator<<(agora::tools::Packer &p,
const ServiceStreaming *x) {
p << dynamic_cast<const Service *>(x) << x->channel_name_ << x->account_;
return p;
}

friend agora::tools::Unpacker &operator>>(agora::tools::Unpacker &p,
ServiceStreaming *x) {
p >> dynamic_cast<Service *>(x) >> x->channel_name_ >> x->account_;
return p;
}

public:
std::string channel_name_;
std::string account_;

protected:
ServiceStreaming(const ServiceStreaming &) = default;
ServiceStreaming(ServiceStreaming &&) = default;
ServiceStreaming &operator=(const ServiceStreaming &) = default;
ServiceStreaming &operator=(ServiceStreaming &&) = default;
};

class ServiceFpa : public Service {
public:
enum {
kServiceType = 4,

kPrivilegeLogin = 1,
};

ServiceFpa() : Service(kServiceType) {}

virtual std::string PackService() override { return Pack(this); }
virtual void UnpackService(Unpacker *unpacker) override { *unpacker >> this; }

virtual std::unique_ptr<Service> Clone() const override {
return std::unique_ptr<Service>(new ServiceFpa(*this));
}

friend agora::tools::Packer &operator<<(agora::tools::Packer &p,
const ServiceFpa *x) {
return p << dynamic_cast<const Service *>(x);
}
friend agora::tools::Unpacker &operator>>(agora::tools::Unpacker &p,
ServiceFpa *x) {
return p >> dynamic_cast<Service *>(x);
}

protected:
ServiceFpa(const ServiceFpa &) = default;
ServiceFpa(ServiceFpa &&) = default;
ServiceFpa &operator=(const ServiceFpa &) = default;
ServiceFpa &operator=(ServiceFpa &&) = default;
};

class ServiceChat : public Service {
public:
enum {
Expand Down Expand Up @@ -282,9 +154,6 @@ struct ServiceCreator {
};
static const std::map<uint16_t, Service *(*)()> kServiceCreator = {
{ServiceRtc::kServiceType, ServiceCreator<ServiceRtc>::New},
{ServiceRtm::kServiceType, ServiceCreator<ServiceRtm>::New},
{ServiceStreaming::kServiceType, ServiceCreator<ServiceStreaming>::New},
{ServiceFpa::kServiceType, ServiceCreator<ServiceFpa>::New},
{ServiceChat::kServiceType, ServiceCreator<ServiceChat>::New},
};

Expand Down
47 changes: 0 additions & 47 deletions DynamicKey/AgoraDynamicKey/cpp/src/FpaTokenBuilder.h

This file was deleted.

42 changes: 24 additions & 18 deletions DynamicKey/AgoraDynamicKey/cpp/src/RtcTokenBuilder2.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,21 @@ class RtcTokenBuilder2 {
In order for this role to take effect, please contact our support team to
enable authentication for Hosting-in for you. Otherwise, Role_Subscriber
still has the same privileges as Role_Publisher.
@param expire represented by the number of seconds elapsed since now. If, for
example, you want to access the Agora Service within 10 minutes after the
token is generated (both for token life cycle and privilege life cycle),
set expireTimestamp as 600(seconds).
@param token_expire represented by the number of seconds elapsed since now. If,
for example, you want to access the Agora Service within 10 minutes after the
token is generated, set token_expire as 600(seconds).
@param privilege_expire represented by the number of seconds elapsed since now. If, for
example, you want to enable your privilege for 10 minutes, set privilege_expire
as 600(seconds).
@return The new Token.
*/

static std::string BuildTokenWithUid(const std::string& app_id,
const std::string& app_certificate,
const std::string& channel_name,
uint32_t uid, UserRole role,
uint32_t expire = 0);
uint32_t token_expire,
uint32_t privilege_expire = 0);

/**
Builds an RTC token using a string userAccount.
Expand All @@ -94,16 +98,18 @@ class RtcTokenBuilder2 {
In order for this role to take effect, please contact our support team to
enable authentication for Hosting-in for you. Otherwise, Role_Subscriber
still has the same privileges as Role_Publisher.
@param expire represented by the number of seconds elapsed since now. If, for
example, you want to access the Agora Service within 10 minutes after the
token is generated, (both for token life cycle and privilege life cycle),
set expireTimestamp as 600(seconds).
@param token_expire represented by the number of seconds elapsed since now. If,
for example, you want to access the Agora Service within 10 minutes after the
token is generated, set token_expire as 600(seconds).
@param privilege_expire represented by the number of seconds elapsed since now. If, for
example, you want to enable your privilege for 10 minutes, set privilege_expire
as 600(seconds).
@return The new Token.
*/
static std::string BuildTokenWithUserAccount(
const std::string& app_id, const std::string& app_certificate,
const std::string& channel_name, const std::string& user_account,
UserRole role, uint32_t expire = 0);
UserRole role, uint32_t token_expire, uint32_t privilege_expire = 0);

/**
* Generates a RTC token with specified privileges.
Expand Down Expand Up @@ -214,29 +220,29 @@ class RtcTokenBuilder2 {
inline std::string RtcTokenBuilder2::BuildTokenWithUid(
const std::string& app_id, const std::string& app_certificate,
const std::string& channel_name, uint32_t uid, UserRole role,
uint32_t expire) {
uint32_t token_expire, uint32_t privilege_expire) {
std::string account;
if (uid != 0) {
account = std::to_string(uid);
}
return RtcTokenBuilder2::BuildTokenWithUserAccount(
app_id, app_certificate, channel_name, account, role, expire);
app_id, app_certificate, channel_name, account, role, token_expire, privilege_expire);
}

inline std::string RtcTokenBuilder2::BuildTokenWithUserAccount(
const std::string& app_id, const std::string& app_certificate,
const std::string& channel_name, const std::string& user_account,
UserRole role, uint32_t expire) {
UserRole role, uint32_t token_expire, uint32_t privilege_expire) {
std::unique_ptr<Service> service(
new ServiceRtc(channel_name, user_account));
service->AddPrivilege(ServiceRtc::kPrivilegeJoinChannel, expire);
service->AddPrivilege(ServiceRtc::kPrivilegeJoinChannel, privilege_expire);
if (role == UserRole::kRolePublisher) {
service->AddPrivilege(ServiceRtc::kPrivilegePublishAudioStream, expire);
service->AddPrivilege(ServiceRtc::kPrivilegePublishVideoStream, expire);
service->AddPrivilege(ServiceRtc::kPrivilegePublishDataStream, expire);
service->AddPrivilege(ServiceRtc::kPrivilegePublishAudioStream, privilege_expire);
service->AddPrivilege(ServiceRtc::kPrivilegePublishVideoStream, privilege_expire);
service->AddPrivilege(ServiceRtc::kPrivilegePublishDataStream, privilege_expire);
}

AccessToken2 generator(app_id, app_certificate, 0, expire);
AccessToken2 generator(app_id, app_certificate, 0, token_expire);
generator.AddService(std::move(service));

return generator.Build();
Expand Down
47 changes: 0 additions & 47 deletions DynamicKey/AgoraDynamicKey/cpp/src/RtmTokenBuilder2.h

This file was deleted.

Loading