Codeigniter, Restful API & How to use Keys












7















I am using Phil Sturgeon's & Chris Kacerguis Restful server (visit here https://github.com/chriskacerguis/codeigniter-restserver) and have a general question about the use of API KEYS. I am very new to APIs and the concepts.



How do KEYS work? There is a table called KEYS defined as follows:



| Default table schema:
| CREATE TABLE `keys` (
| `id` INT(11) NOT NULL AUTO_INCREMENT,
| `user_id` INT(11) NOT NULL,
| `key` VARCHAR(40) NOT NULL,
| `level` INT(2) NOT NULL,
| `ignore_limits` TINYINT(1) NOT NULL DEFAULT '0',
| `is_private_key` TINYINT(1) NOT NULL DEFAULT '0',
| `ip_addresses` TEXT NULL DEFAULT NULL,
| `date_created` INT(11) NOT NULL,
| PRIMARY KEY (`id`)
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8;


There are methods in a class called KEYS as follows:



index_put() // key created.  builds a new key.
index_delete() // Remove a key from the database to stop it working.
level_post() // Update Key. Change the level.
suspend_post() // Update Key. Change the level.
regenerate_post() // Regenerate key. Remove a key from the database to stop it working.


As this package is not well documented and I am new to API, how does above work? For example, do I generate 1 key and insert it to the db permanently. Why is there a delete methods?



From my readings, it sounds like I generate an initial X-API-KEY for the app and then when the client uses a resource I would swap the X-API-KEY for another key using the KEYS class. I would delete it, too, but when? ... or am I all screwed up in my understanding?










share|improve this question



























    7















    I am using Phil Sturgeon's & Chris Kacerguis Restful server (visit here https://github.com/chriskacerguis/codeigniter-restserver) and have a general question about the use of API KEYS. I am very new to APIs and the concepts.



    How do KEYS work? There is a table called KEYS defined as follows:



    | Default table schema:
    | CREATE TABLE `keys` (
    | `id` INT(11) NOT NULL AUTO_INCREMENT,
    | `user_id` INT(11) NOT NULL,
    | `key` VARCHAR(40) NOT NULL,
    | `level` INT(2) NOT NULL,
    | `ignore_limits` TINYINT(1) NOT NULL DEFAULT '0',
    | `is_private_key` TINYINT(1) NOT NULL DEFAULT '0',
    | `ip_addresses` TEXT NULL DEFAULT NULL,
    | `date_created` INT(11) NOT NULL,
    | PRIMARY KEY (`id`)
    | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;


    There are methods in a class called KEYS as follows:



    index_put() // key created.  builds a new key.
    index_delete() // Remove a key from the database to stop it working.
    level_post() // Update Key. Change the level.
    suspend_post() // Update Key. Change the level.
    regenerate_post() // Regenerate key. Remove a key from the database to stop it working.


    As this package is not well documented and I am new to API, how does above work? For example, do I generate 1 key and insert it to the db permanently. Why is there a delete methods?



    From my readings, it sounds like I generate an initial X-API-KEY for the app and then when the client uses a resource I would swap the X-API-KEY for another key using the KEYS class. I would delete it, too, but when? ... or am I all screwed up in my understanding?










    share|improve this question

























      7












      7








      7








      I am using Phil Sturgeon's & Chris Kacerguis Restful server (visit here https://github.com/chriskacerguis/codeigniter-restserver) and have a general question about the use of API KEYS. I am very new to APIs and the concepts.



      How do KEYS work? There is a table called KEYS defined as follows:



      | Default table schema:
      | CREATE TABLE `keys` (
      | `id` INT(11) NOT NULL AUTO_INCREMENT,
      | `user_id` INT(11) NOT NULL,
      | `key` VARCHAR(40) NOT NULL,
      | `level` INT(2) NOT NULL,
      | `ignore_limits` TINYINT(1) NOT NULL DEFAULT '0',
      | `is_private_key` TINYINT(1) NOT NULL DEFAULT '0',
      | `ip_addresses` TEXT NULL DEFAULT NULL,
      | `date_created` INT(11) NOT NULL,
      | PRIMARY KEY (`id`)
      | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;


      There are methods in a class called KEYS as follows:



      index_put() // key created.  builds a new key.
      index_delete() // Remove a key from the database to stop it working.
      level_post() // Update Key. Change the level.
      suspend_post() // Update Key. Change the level.
      regenerate_post() // Regenerate key. Remove a key from the database to stop it working.


      As this package is not well documented and I am new to API, how does above work? For example, do I generate 1 key and insert it to the db permanently. Why is there a delete methods?



      From my readings, it sounds like I generate an initial X-API-KEY for the app and then when the client uses a resource I would swap the X-API-KEY for another key using the KEYS class. I would delete it, too, but when? ... or am I all screwed up in my understanding?










      share|improve this question














      I am using Phil Sturgeon's & Chris Kacerguis Restful server (visit here https://github.com/chriskacerguis/codeigniter-restserver) and have a general question about the use of API KEYS. I am very new to APIs and the concepts.



      How do KEYS work? There is a table called KEYS defined as follows:



      | Default table schema:
      | CREATE TABLE `keys` (
      | `id` INT(11) NOT NULL AUTO_INCREMENT,
      | `user_id` INT(11) NOT NULL,
      | `key` VARCHAR(40) NOT NULL,
      | `level` INT(2) NOT NULL,
      | `ignore_limits` TINYINT(1) NOT NULL DEFAULT '0',
      | `is_private_key` TINYINT(1) NOT NULL DEFAULT '0',
      | `ip_addresses` TEXT NULL DEFAULT NULL,
      | `date_created` INT(11) NOT NULL,
      | PRIMARY KEY (`id`)
      | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;


      There are methods in a class called KEYS as follows:



      index_put() // key created.  builds a new key.
      index_delete() // Remove a key from the database to stop it working.
      level_post() // Update Key. Change the level.
      suspend_post() // Update Key. Change the level.
      regenerate_post() // Regenerate key. Remove a key from the database to stop it working.


      As this package is not well documented and I am new to API, how does above work? For example, do I generate 1 key and insert it to the db permanently. Why is there a delete methods?



      From my readings, it sounds like I generate an initial X-API-KEY for the app and then when the client uses a resource I would swap the X-API-KEY for another key using the KEYS class. I would delete it, too, but when? ... or am I all screwed up in my understanding?







      php rest codeigniter api restful-authentication






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 12 '16 at 5:39









      spreadermanspreaderman

      158116




      158116
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Lots of good questions here.




          "How do KEYS work?"




          A RESTful API service can serve a number of different users, so the API key is an individual key to grant access to the REST API. This allows the service administrator to grant or revoke access to different users or modify permissions granted to each user.




          "Why is there a delete method?"




          This is in place to revoke API access for a specific key. There could be a number of reasons why this would be used. Perhaps the API user violated the terms of service, or if it's a paid service perhaps their subscription has ended or been revoked. It allows the administrator to cancel a user's access to the API service. This should also answer your question of "when?"






          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40559942%2fcodeigniter-restful-api-how-to-use-keys%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Lots of good questions here.




            "How do KEYS work?"




            A RESTful API service can serve a number of different users, so the API key is an individual key to grant access to the REST API. This allows the service administrator to grant or revoke access to different users or modify permissions granted to each user.




            "Why is there a delete method?"




            This is in place to revoke API access for a specific key. There could be a number of reasons why this would be used. Perhaps the API user violated the terms of service, or if it's a paid service perhaps their subscription has ended or been revoked. It allows the administrator to cancel a user's access to the API service. This should also answer your question of "when?"






            share|improve this answer






























              1














              Lots of good questions here.




              "How do KEYS work?"




              A RESTful API service can serve a number of different users, so the API key is an individual key to grant access to the REST API. This allows the service administrator to grant or revoke access to different users or modify permissions granted to each user.




              "Why is there a delete method?"




              This is in place to revoke API access for a specific key. There could be a number of reasons why this would be used. Perhaps the API user violated the terms of service, or if it's a paid service perhaps their subscription has ended or been revoked. It allows the administrator to cancel a user's access to the API service. This should also answer your question of "when?"






              share|improve this answer




























                1












                1








                1







                Lots of good questions here.




                "How do KEYS work?"




                A RESTful API service can serve a number of different users, so the API key is an individual key to grant access to the REST API. This allows the service administrator to grant or revoke access to different users or modify permissions granted to each user.




                "Why is there a delete method?"




                This is in place to revoke API access for a specific key. There could be a number of reasons why this would be used. Perhaps the API user violated the terms of service, or if it's a paid service perhaps their subscription has ended or been revoked. It allows the administrator to cancel a user's access to the API service. This should also answer your question of "when?"






                share|improve this answer















                Lots of good questions here.




                "How do KEYS work?"




                A RESTful API service can serve a number of different users, so the API key is an individual key to grant access to the REST API. This allows the service administrator to grant or revoke access to different users or modify permissions granted to each user.




                "Why is there a delete method?"




                This is in place to revoke API access for a specific key. There could be a number of reasons why this would be used. Perhaps the API user violated the terms of service, or if it's a paid service perhaps their subscription has ended or been revoked. It allows the administrator to cancel a user's access to the API service. This should also answer your question of "when?"







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 21 '18 at 6:13









                lagom

                3,651102037




                3,651102037










                answered Nov 21 '18 at 5:51









                tshimkustshimkus

                344216




                344216






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40559942%2fcodeigniter-restful-api-how-to-use-keys%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                    Alcedinidae

                    RAC Tourist Trophy