This is a migrated thread and some comments may be shown as answers.

.NET SDK get Segments from Backend services

7 Answers 76 Views
Push Notifications
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Carlos
Top achievements
Rank 1
Carlos asked on 20 Aug 2015, 05:34 PM

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

7 Answers, 1 is accepted

Sort by
0
Matt
Top achievements
Rank 1
answered on 20 Aug 2015, 07:57 PM

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;
            };

0
Dimitar Dimitrov
Telerik team
answered on 21 Aug 2015, 01:04 PM
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.
 
0
Matt
Top achievements
Rank 1
answered on 21 Aug 2015, 04:23 PM

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;
            };

0
Matt
Top achievements
Rank 1
answered on 21 Aug 2015, 04:33 PM
btw, i'm using the c# 4.5 telerik.everlive.sdk
0
Anton Dobrev
Telerik team
answered on 24 Aug 2015, 03:39 PM
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.
 
0
Matt
Top achievements
Rank 1
answered on 24 Aug 2015, 07:47 PM

that did the trick!  thanks a ton!

Matt

0
Anton Dobrev
Telerik team
answered on 25 Aug 2015, 10:39 AM
@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.
 
Tags
Push Notifications
Asked by
Carlos
Top achievements
Rank 1
Answers by
Matt
Top achievements
Rank 1
Dimitar Dimitrov
Telerik team
Anton Dobrev
Telerik team
Share this question
or