.NET SDK get Segments from Backend services

8 posts, 0 answers
  1. Carlos
    Carlos avatar
    69 posts
    Member since:
    Jun 2011

    Posted 20 Aug 2015 Link to this post

    We are using the .NET SDK to access the Backend Services.  We are writing and interface into our CMS that we can use for our general editors so they can write Push Notifications through our .NET CMS we are using.  

    We have a C# file that we are trying to access the Segments portion of the Push Notifications service.  We keep getting Access Denied when we try to access the Push Notifications service. We know we are getting to Telerik Backend Services,  and we have our API key set up correctly because we have tried hitting some tables we set up manually in the BaaS, but when we try to get the Push Notifications table to get a list of registered devices or a list of the segments, we get an access denied error.  

     The documentation is kind of sparse on how to achieve most of this.

     Any pointers?

     

    Thanks,

     

    Carlos

  2. Matt
    Matt avatar
    17 posts
    Member since:
    Jun 2015

    Posted 20 Aug 2015 in reply to Carlos Link to this post

    Not an answer but more details to the problem.  I'm working with Carlos on this problem.  specifically, i've used our general API Key in the everlive appsettings (code snippets below).  when i do this and then attempt to use the C# SDK to access the Users() table, i successfully get counts, user data, etc.  when i try to access the Push() functions (getting notification count, device count, details, etc.) i get 'Access denied'.  further, i tried using our Master Key and i get 'Invalid API Key' error when trying to do anything.  i regenerated our Master Key with the same result.  below is how i'm doing our function test.  note, i'm using Sync (vs. Async) as i do need to hold moving forward until i actually get the data response from telerik.  at this point, i'm not worried about sync/async.  i just want to prove i can get the device info back so we can gather the custom parameters registered by our client device application.

     

    var appSettings = new EverliveAppSettings() {
                    ApiKey = "​<our key here>",
                    UseHttps = true
                };
    var everliveApp = new EverliveApp(appSettings);

     

    var deviceList = everliveApp.WorkWith().Push().Devices().GetAll().TryExecuteSync();            
                if (deviceList.Success)
                {
                    var bob = deviceList.Value;
                }
                else
                {
                    EverliveException err = deviceList.Error;
                };

  3. Dimitar Dimitrov
    Admin
    Dimitar Dimitrov avatar
    26 posts

    Posted 21 Aug 2015 Link to this post

    Hello,

    The devices data is protected and you have to authorize in order to get it. You were correct to use the MasterKey, but most probably you misused it as an ApiKey. The MasterKey is private and should not be put in public, as it is a valid authorization to get all of the protected resources of your application.

    Here is the documentation article that explains how to use the MasterKey authorization in the .NET SDK- link.

    That should resolve the problem with getting the list of devices.

    If you have more issues, do not hesitate to contact us.

    Regards,
    Dimitar Dimitrov
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
  4. Matt
    Matt avatar
    17 posts
    Member since:
    Jun 2015

    Posted 21 Aug 2015 in reply to Dimitar Dimitrov Link to this post

    this is exactly the info i was looking for.  thanks a ton for pointing it out.  can't believe i missed that part of the documentation.  this use of the masterkey is actually on one of our internal servers used as a management console so very protected from abuse or hacking.

     unfortunately, i still have a failure -- it doesn't work.  specifically, when i step through my Visual Studio debugger, as soon as i attempt to assign app.AccessToken.Token = "<my master token>", the debugger stops tracking the flow.  it doesn't break, the debugger is still running, the application still runs.  my code just doesn't continue past any attempt to mess with AccessToken.  consequently, i cannot run anything against the telerik tables to retrieve data.  i noticed just before attempting to assign the .Token (or .TokenType for that matter), the app.AccessToken object is 'null'.  i expected to see the Token and TokenType structure vs. a 'null'.  i didn't find anything in the documentation on the link that suggests other steps.  am i still missing something?

     

    thanks

    matt

     

    Sample code:

    var appSettings = new EverliveAppSettings()
                {
                    ApiKey = "​<our normal api key>",
                    UseHttps = true
                };
                var telerikApp = new EverliveApp(appSettings);
                telerikApp.AccessToken.Token = "<our master key>"; //NOTE: debugger stops stepping through code here and will not continue
                telerikApp.AccessToken.TokenType = "Masterkey";

                
                var deviceList = telerikApp.WorkWith().Push().Devices().GetAll().TryExecuteSync();
                
                if (deviceList.Success)
                {
                    var bob = deviceList.Value;  //used just to provide an object list i can then start to understand and manipulate
                }
                else
                {
                    EverliveException err = deviceList.Error;
                };

  5. Matt
    Matt avatar
    17 posts
    Member since:
    Jun 2015

    Posted 21 Aug 2015 in reply to Matt Link to this post

    btw, i'm using the c# 4.5 telerik.everlive.sdk
  6. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 24 Aug 2015 Link to this post

    Hi Matt,

    Could you please replace this code:
    telerikApp.AccessToken.Token = "<our master key>"; //NOTE: debugger stops stepping through code here and will not continue
    telerikApp.AccessToken.TokenType = "Masterkey";

    with this one:
    telerikApp.AccessToken = new AccessToken("your-master-key-here", "MasterKey");

    The documentation will also be corrected on our side. I updated your Telerk Points 
    as a small token of gratitude for helping us out.

    Regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
  7. Matt
    Matt avatar
    17 posts
    Member since:
    Jun 2015

    Posted 24 Aug 2015 in reply to Anton Dobrev Link to this post

    that did the trick!  thanks a ton!

    Matt

  8. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 25 Aug 2015 Link to this post

    @Matt

    You are welcome, I am sorry about the confusion with the initial code snippet.

    Let us know if you have questions.

    Regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
Back to Top