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

Using Master Key to create DataItems

4 Answers 113 Views
.NET SDK
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mischa
Top achievements
Rank 1
Mischa asked on 25 Oct 2013, 11:48 AM
I'm trying to add DataItems using only my Master Key (no username / password), but I get the following error: "CREATE access on type 'MyType' denied for anonymous user".

I got the following from the EverLive portal regarding the Master Key: "The Master Key can be used to bypass application security and grant you access to manage your Everlive app from a service similar to the Everlive portal."

I've set the permissions on my type to "Read-Only" because I'll only be creating and updating them from a backend application.

4 Answers, 1 is accepted

Sort by
0
Lyubomir Dokov
Telerik team
answered on 25 Oct 2013, 01:05 PM
Hello Mischa,

Can you please share the code that makes the connection to Everlive and how you supply the master key? Of course, you should replace the actual master key with ### or something, so that it is not visible to everyone.

On a side note, you concept is correct - using master key with read-only permissions on the content type. This ensures that users of your Everlive app can only read data from the content type, but only you can insert, update or delete items.


Regards,
Lyubomir Dokov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Mischa
Top achievements
Rank 1
answered on 25 Oct 2013, 01:21 PM
Hi Lyubomir,

Here's my code:

EverliveAppSettings eAppSettings = new EverliveAppSettings()
{
    ApiKey = "MyApp_ApiKey"
};

eApp = new EverliveApp(eAppSettings);
eApp.WorkWith().Authentication().Login("MyApp_MasterKey");
eApp.WorkWith().Data<MyClass>().Create(myClass).ExecuteSync();
0
Accepted
Lyubomir Dokov
Telerik team
answered on 25 Oct 2013, 02:00 PM
Hello Mischa,

I can see the problem now. It is in the following line:
eApp.WorkWith().Authentication().Login("MyApp_MasterKey");

You are not actually executing this login request. The login request is just like any other Everlive service request - it is asynchronous and you must either await it or execute it synchronously. This means that you should have something like this:
 eApp.WorkWith().Authentication().Login("MyApp_MasterKey");.ExecuteSync();

 After this line completes, all following requests to Everlive will be made using masterkey authentication.


Regards,
Lyubomir Dokov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Mischa
Top achievements
Rank 1
answered on 25 Oct 2013, 02:14 PM
Got it! It's now working, here's the code:

EverliveAppSettings eAppSettings = new EverliveAppSettings()
{
    ApiKey = "MyApp_ApiKey"
};

eApp = new EverliveApp(eAppSettings);
eApp.WorkWith().Authentication().Login("MyApp_MasterKey").ExecuteSync();
eApp.WorkWith().Data<MyClass>().Create(myClass).ExecuteSync();
Tags
.NET SDK
Asked by
Mischa
Top achievements
Rank 1
Answers by
Lyubomir Dokov
Telerik team
Mischa
Top achievements
Rank 1
Share this question
or