Tools icon indicating copy to clipboard operation
Tools copied to clipboard

I am using csharp code to generate the access token but this token is not working when i try to join a call

Open fullstack10 opened this issue 4 years ago • 25 comments

image

fullstack10 avatar Mar 01 '21 08:03 fullstack10

I also run into the same issue. Any help ? I'm using the code below to generate my token:

AccessToken token = new AccessToken(_appId, _appCertificate, _channelName, _uid, _ts, _salt);
token.message.ts = _ts;
token.message.salt = _salt;
token.addPrivilege(Privileges.kJoinChannel, _expiredTs);

string result = token.build();

image

Hoang-Minh avatar Nov 10 '21 22:11 Hoang-Minh

The c# code is broken. I was able to generate the token by using node js. Please fix the package to generate code in c#. Thank you !!!

Hoang-Minh avatar Nov 11 '21 00:11 Hoang-Minh

i just prefix variable values in accesstoken.cs class which is mentioned below ,

    private uint _ts = 1111111;
    private uint _salt = 1;
    private uint _expiredTs = 1446455471;
    
    and while calling    AccessToken token = new AccessToken(appId, appCertificate, channelName, uid, ts, salt);

i am passing uid = "0"; and its working

string uid = "0"; means you can use the same token for connecting a video call specific uid means you need two / more different access token to connect video call

fullstack10 avatar Nov 11 '21 06:11 fullstack10

Thanks @fullstack10 . Its not working for me even if I passed uid = "0". This is my generated token when passing uid = "0". However, when I used it for the demo (https://github.com/AgoraIO-Community/AgoraWebSDK-NG) it is not working. 0063fb869e0755144ae9cd4a714201cf921IAA2bQNquudi3rrKnZFQfe6VdO/mPvqiZPHswcCB1DZuJlsFw2wh39v0EAABAAAAR/QQAAEAAQCvKDdW

What does your token look like @fullstack10 ? Thank you

Hoang-Minh avatar Nov 11 '21 18:11 Hoang-Minh

hi @Hoang-Minh , i am using https://github.com/AgoraIO/Tools/tree/master/DynamicKey/AgoraDynamicKey/csharp this code , and my token is 006970CA35de60c44645bbae8a215061b33IADNg9bfcUDIC1Qs1EedxluwYPEhU8Z66b8WHMWwqz0L9wx+f9gh39v0EAABAAAAR/QQAAEAAQCvKDdW image

fullstack10 avatar Nov 12 '21 06:11 fullstack10

@fullstack10 Have you tried to use your key with the demo ? https://webdemo.agora.io/agora-web-showcase/examples/Agora-Web-Tutorial-1to1-Web/

For me, key cannot be used to join if using csharp. However, if I use the key generated from nodejs then it's working for me.

Hoang-Minh avatar Nov 12 '21 18:11 Hoang-Minh

Yes I tried and now i am using this in my live project and its working

On Sat, 13 Nov 2021 at 12:09 AM, Hoang Minh @.***> wrote:

@fullstack10 https://github.com/fullstack10 Have you tried to use your key with the demo ?

https://webdemo.agora.io/agora-web-showcase/examples/Agora-Web-Tutorial-1to1-Web/

For me, key cannot be used to join if using csharp. However, if I use the key generated from nodejs then it's working for me.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AgoraIO/Tools/issues/131#issuecomment-967333287, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQR3OAGSPSJXKUAZOE7WBLDULVNNDANCNFSM4YMFR52A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

fullstack10 avatar Nov 13 '21 06:11 fullstack10

@fullstack10 hmmm, that is so weird. It does not work for me at all. Its giving me this error in c# image

@yoreland Can you help me out please ? Thank you

Hoang-Minh avatar Nov 15 '21 18:11 Hoang-Minh

Hi can you please provide me your appid and app secret so i will create a token for you and tested with my code if anything different then i will update you . On Mon, 15 Nov 2021 at 11:48 PM, Hoang Minh @.***> wrote:

@fullstack10 https://github.com/fullstack10 hmmm, that is so weird. It does not work for me at all. Its giving me this error in c# [image: image] https://user-images.githubusercontent.com/8659719/141833486-745a4d1e-8ef3-4871-86e7-be049b9ac06d.png

@yoreland https://github.com/yoreland Can you help me out please ? Thank you

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AgoraIO/Tools/issues/131#issuecomment-969187717, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQR3OAFM2KKPV6ZF2B2WBBLUMFFH7ANCNFSM4YMFR52A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

fullstack10 avatar Nov 16 '21 06:11 fullstack10

@fullstack10 what is your email ? Thank you

Hoang-Minh avatar Nov 16 '21 07:11 Hoang-Minh

Email : @.*** On Tue, 16 Nov 2021 at 12:32 PM, Hoang Minh @.***> wrote:

@fullstack10 https://github.com/fullstack10 what is your email ? Thank you

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AgoraIO/Tools/issues/131#issuecomment-969934258, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQR3OAHMIJEXHLUJ4XFZS2DUMH6W3ANCNFSM4YMFR52A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

fullstack10 avatar Nov 16 '21 07:11 fullstack10

I think Github censors your email. Anyway, here is my agora info:

AppId: 3fb869e0755144ae9cd4a714201cf921
AppCertificate: edb6e4236aec4bf7a181898255dec8da

Thank you

Hoang-Minh avatar Nov 16 '21 07:11 Hoang-Minh

hi , just replace below method in accesstoken.cs class. then it starts working.

accesstoken.cs

public void addPrivilege(Privileges kJoinChannel, uint expiredTs) { // this.message.messages.Add((ushort)kJoinChannel, expiredTs); }

[image: image.png]

On Tue, Nov 16, 2021 at 1:09 PM Hoang Minh @.***> wrote:

I think Github censors your email. Anyway, here is my agora info:

AppId: 3fb869e0755144ae9cd4a714201cf921 AppCertificate: edb6e4236aec4bf7a181898255dec8da

Thank you

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AgoraIO/Tools/issues/131#issuecomment-969964338, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQR3OADPDQURY4AIPUIGCOLUMIDEZANCNFSM4YMFR52A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

fullstack10 avatar Nov 16 '21 09:11 fullstack10

Hmmm, commenting that part of code out will take out the privilege and expire time for your token. It will have impact on the generated token. I thought you said that the code is working for you without commenting that out ? Am I correct ? Thank you

Hoang-Minh avatar Nov 16 '21 17:11 Hoang-Minh

I tried with expiration time as well but its not working and then i did this but the token which we generated from this code with comment this line it will expire in 24 hours so its work for me.

On Tue, 16 Nov 2021 at 11:22 PM, Hoang Minh @.***> wrote:

Hmmm, commenting that part of code out will take out the privilege and expire time for your token. It will have impact on the generated token. I thought you said that the code is working for you without commenting that out ? Am I correct ? Thank you

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AgoraIO/Tools/issues/131#issuecomment-970518676, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQR3OAGCDSKIT45KFMAKMVTUMKK5FANCNFSM4YMFR52A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

fullstack10 avatar Nov 17 '21 03:11 fullstack10

Got it. Thank you @fullstack10

Hoang-Minh avatar Nov 17 '21 16:11 Hoang-Minh

@fullstack10 FYI, my token is still not working even though I have commented the code that you said. @yoreland : Are not not supporting/maintaining this package anymore ? I've been asking for help for more than a week and I have not got any response yet.

Hoang-Minh avatar Nov 18 '21 18:11 Hoang-Minh

I will send you a code just use that and try again.

On Thu, 18 Nov 2021 at 11:38 PM, Hoang Minh @.***> wrote:

@fullstack10 https://github.com/fullstack10 FYI, my token is still not working even though I have commented the code that you said. @yoreland https://github.com/yoreland : Are not not supporting/maintaining this package anymore ? I've been asking for help for more than a week and I have not got any response yet.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AgoraIO/Tools/issues/131#issuecomment-973126571, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQR3OADN6B7FFWJDE7EZA23UMU6JLANCNFSM4YMFR52A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

fullstack10 avatar Nov 18 '21 18:11 fullstack10

Thank you @fullstack10

Hoang-Minh avatar Nov 18 '21 18:11 Hoang-Minh

@fullstack10 I figured out how to generate a token with expiration time. The problem lies in the _ts and _salt value. We need not to pass them in to the access token constructor. Below is my snippet code:

      ` var expireTime = 3600;
        var test = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
        _expiredTs = (uint)(test + expireTime);

        string expected = "006970CA35de60c44645bbae8a215061b33IACV0fZUBw+72cVoL9eyGGh3Q6Poi8bgjwVLnyKSJyOXR7dIfRBXoFHlEAABAAAAR/QQAAEAAQCvKDdW";
        
        AccessToken token = new AccessToken(_appId, _appCertificate, _channelName, _uid);

        token.addPrivilege(Privileges.kJoinChannel, _expiredTs);
        string result = token.build();
        Assert.Equal(expected, result);`

Hoang-Minh avatar Nov 19 '21 07:11 Hoang-Minh

Great , thank you so much now do you need the c# code. On Fri, 19 Nov 2021 at 1:27 PM, Hoang Minh @.***> wrote:

@fullstack10 https://github.com/fullstack10 I figured out how to generate a token with expiration time. The problem lies in the _ts and _salt value. We need not to pass them in to the access token constructor. Below is my snippet code:

` var expireTime = 3600; var test = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds(); _expiredTs = (uint)(test + expireTime);

    string expected = "006970CA35de60c44645bbae8a215061b33IACV0fZUBw+72cVoL9eyGGh3Q6Poi8bgjwVLnyKSJyOXR7dIfRBXoFHlEAABAAAAR/QQAAEAAQCvKDdW";

    AccessToken token = new AccessToken(_appId, _appCertificate, _channelName, _uid);

    token.addPrivilege(Privileges.kJoinChannel, _expiredTs);
    string result = token.build();
    Assert.Equal(expected, result);`

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AgoraIO/Tools/issues/131#issuecomment-973841841, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQR3OACYFWI7CUVM7SFDHLTUMX7OXANCNFSM4YMFR52A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

fullstack10 avatar Nov 19 '21 07:11 fullstack10

It would be nice too, if you can. Thank you very much

Hoang-Minh avatar Nov 19 '21 08:11 Hoang-Minh

https://drive.google.com/file/d/1gZxSQHHWqpvc6hFkod0FUNExiHes_XKq/view?usp=sharing

On Fri, Nov 19, 2021 at 1:41 PM Hoang Minh @.***> wrote:

It would be nice too, if you can. Thank you very much

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AgoraIO/Tools/issues/131#issuecomment-973850137, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQR3OAGLPT74WJR24GOWBY3UMYBBZANCNFSM4YMFR52A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

fullstack10 avatar Nov 20 '21 07:11 fullstack10

Thanks @fullstack10

Hoang-Minh avatar Nov 22 '21 17:11 Hoang-Minh

Hi @ken39arg,

I getting problem of expiring time.

My code for generating the token in the dotnet, below is my code.

public AgoraResponseDto testGenerateDynamicKey(AgoraRequestDto agoraRequestDto)
        {
            AgoraResponseDto agoraResponseTest = new AgoraResponseDto();

            var expireTime = 3600;
            var test = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
             _expiredTs = (uint)(test + expireTime);


            //string expected = "006970CA35de60c44645bbae8a215061b33IACV0fZUBw+72cVoL9eyGGh3Q6Poi8bgjwVLnyKSJyOXR7dIfRBXoFHlEAABAAAAR/QQAAEAAQCvKDdW";
            AccessToken token = new AccessToken(_appId, _appCertificate, _channelName, _uid, _ts, _salt);
            token.message.ts = _ts;
            token.message.salt = _salt;
            token.addPrivilege(Privileges.kJoinChannel, _expiredTs);

            string result = token.build();
            agoraResponseTest.AppCertificate = _appCertificate;
            agoraResponseTest.AppId = _appId;
            agoraResponseTest.Channel = _channelName;
            agoraResponseTest.Token = result;
            return agoraResponseTest;
        }

and the response is :

{
  "channel": "123456789",
  "appId": "43608641637444738faddaf9f89c62ed",
  "appCertificate": "822e318d19354931900df847f6198bdc",
  "token": "00643608641637444738faddaf9f89c62edIAChf81uxKKNViKXLlpTxPZaprXAH2gn54jJI32c/wILdCY59MtXoFHlEAABAAAAR/QQAAEAAQA/hmpi"
}

![TokenAuthenticationAndTime](https://user-images.githubusercontent.com/104567114/165741622-e426f8b5-e5b4-4117-9315-45c1de960db0.png)
![TokenAuthenticationAndTime](https://user-images.githubusercontent.com/104567114/165741698-4a1c5103-767a-4ef6-9c5a-faa445b3b0cc.png)

TokenAuthenticationAndTime

smnbh12345 avatar Apr 28 '22 11:04 smnbh12345

Change _appId and _appCertificate to the account information you applied for, run the UT of this file https://github.com/AgoraIO/Tools/blob/master/DynamicKey/AgoraDynamicKey/csharp/test/AgoraIO.Tests/RtcTokenBuilderTest.cs. Test the generated token on this website https://webdemo.agora.io/agora-web-showcase/examples/Agora-Web-Tutorial-1to1-Web/

sunshinexcode avatar Jul 18 '24 12:07 sunshinexcode