How to change/setup API Key?

How to change/setup API Key?

by Harley Calvert -
Number of replies: 6
I've got my Jobe running on Debian. It works but how would we setup/change the API Key?

Is it even using the default API key?

I think I found the info here: https://github.com/trampgeek/jobe

It says "You need to be running a PHP version prior to PHP 7.2".

Is there a work-around for that?
In reply to Harley Calvert

Re: How to change/setup API Key?

by Harley Calvert -
Playing around: No, it is not using the default API key.

There's also the rest-server plugin. PHP 7.2 or greater.
In reply to Harley Calvert

Re: How to change/setup API Key?

by Harley Calvert -
So...

CREATE DATABASE jobe;

USE jobe;

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;

DESCRIBE jobe.keys;

Default: 2AAA7A5415B4A9B394B54BF1D2E9D
1E3D8F2A5C7B6A8E1F3B2D7C4E5A6B

INSERT INTO `keys` (`id`, `user_id`, `key`, `level`, `ignore_limits`, `is_private_key`, `ip_addresses`,
`date_created`) VALUES (NULL, '0', '1E3D8F2A5C7B6A8E1F3B2D7C4E5A6B', '0', '0', '0', NULL, CURRENT_TIME());

nano /var/www/html/jobe/application/config/rest.php

$config['rest_enable_keys'] = TRUE;

systemctl restart apache2

Updated the key in Moodle, now I get: 

Failed to run tests

Jobe server request failed. HTTP response from Jobe was 500: null

#############

MysqlI Supportenabled
Client API library versionmysqlnd 8.2.7

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'TBS',
    'password' => 'TBS',
    'database' => 'jobe',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => TRUE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => FALSE
);


In reply to Harley Calvert

Re: How to change/setup API Key?

by Harley Calvert -
Got it!

nano /var/www/html/jobe/application/config/database.php

update username and password for database.
In reply to Harley Calvert

Re: How to change/setup API Key?

by Richard Lobb -
If you want to use API keys, I recommend you pull instead the new JobeV2 branch. This is a major rewrite to use the latest version of CodeIgniter, which offers much better support for RESTful services, API keys, rate throttling, etc. With the new version you don't need to install a database - configuration all takes place in /app/Config/Jobe.php. Much easier.

JobeV2 hasn't officially been released yet - it's a release candidate. But we're running it on a couple of our production servers, including jobe2.cosc.canterbury.ac.nz, which I see you've used.

Thanks for drawing my attention to the comment that you need a PHP version prior to 7.2 when using API keys. That was probably meant to say a version later than 7.2. Sorry about the confusion. You're the only person I know who has tried to set up API keys, so this has never come to light before.

I do wonder why you're worrying about API keys, unless you have a server open to anyone (like our Jobe2). Our normal Jobe servers are VMs on the same hardware as the Moodle server, and are firewalled to allow access only from Moodle.
In reply to Richard Lobb

Re: How to change/setup API Key?

by Harley Calvert -
Thanks for the tip. I'm trying to convince my institute/work to install the plugin. If I can provide them with a maximum security solution, they're more likely to come to the party.

I might be able to just give them a Jobe VM or container if they decide they trust me. Right now, I can make it pretty secure:

  • API Key
  • No SSH (an immutable image or direct access only)
  • Firewall only accepting connections from Moodle VM (could change from default port also)
and depending where it gets deployed:

  • a private subnet with no internet access

I haven't got HTTPS yet, but right now I'm just playing with VMs at home. 

In reply to Richard Lobb

Re: How to change/setup API Key?

by Harley Calvert -
JobeV2 branch seems great. It's really simple to install and setup the API Key. No need for MySQL. The install on Debian came in at ~5GB as opposed to ~6GB for JobeV1 with MySQL. I guess with no MySQL running, it probably uses less resources too.