Using Master Key to create DataItems

5 posts, 1 answers
  1. Mischa
    Mischa avatar
    11 posts
    Member since:
    May 2013

    Posted 25 Oct 2013 Link to this post

    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.

  2. Lyubomir Dokov
    Admin
    Lyubomir Dokov avatar
    43 posts

    Posted 25 Oct 2013 Link to this post

    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.

  3. Mischa
    Mischa avatar
    11 posts
    Member since:
    May 2013

    Posted 25 Oct 2013 Link to this post

    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();
  4. Answer
    Lyubomir Dokov
    Admin
    Lyubomir Dokov avatar
    43 posts

    Posted 25 Oct 2013 Link to this post

    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.

  5. Mischa
    Mischa avatar
    11 posts
    Member since:
    May 2013

    Posted 25 Oct 2013 Link to this post

    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();
Back to Top