CI Authentication via CLI |
Im in the middle of writing an application that can be accessed and used via various methods, such as HTTP, Ajax, cURL, wget, and im hoping to also make it accessible when executed via the command line using php.
I was wondering if anyone has written an application that runs via CLI, that also requires authentication? I get that if they are executing it this way, chances are they already have access to the accounts, but the passwords would be encrypted anyways. Thanks! (10-03-2015, 02:37 PM)skunkbad Wrote: I would start here: Hm, I've never heard of that before, and ill look into it, but does anyone have a way that doesnt require installing more modules? (trying to keep it as easy as possible for those who download the app) Edit: actually, the script I found via google just had a module I dont have, looks like readline is there, ill try it out!
I have a piece of code that shows how CLI authentication could be made.
https://github.com/ivantcholakov/starter...t_user.php You can write something similar/simpler or to try to upgrade a ready solution using the idea. (10-03-2015, 09:24 PM)ivantcholakov Wrote: I have a piece of code that shows how CLI authentication could be made. How exactly is authentication done on the CLI using that?
10-04-2015, 12:24 AM
(This post was last modified: 10-04-2015, 12:35 AM by ivantcholakov. Edit Reason: Typos )
Within the CLI script you can call
Code: $success = $this->current_user->login_by_id(2); // 2 is the user id, it can be taken from a configuration file. Code: $success = $this->current_user->login($username, $password); // The same user, username and password can be taken from a configuration file. login_by_id() is better for this purpose. Let us say you have a special user, that is to be logged through CLI: id: 2 username: robot password: $2F94934860394860348609645690 first_name: I last_name: Robot system_account: 1 // 0 means a normal account used by a human being. For system accounts like this, logging-in from web should be disabled. And then your cron-tasks can use this account for logging-in. If some task modifies some data, then the system account id will be stored within the corresponding "created_by" and "modified_by" fields (if you implement such tracking). You will know then which data has been changed by a normal user and which data - automatically, by a cron-task. |
Welcome Guest, Not a member yet? Register Sign In |