Discussion:
Create API key for a user programmatically
b***@gmail.com
2018-07-07 12:42:41 UTC
Permalink
TL;DR Can API key for a user be created through REST API with credentials of superadmin?

I have a backend system with its own AUTH mechanism. Users can be added and removed dynamically. I am using bugzilla for managing support tickets. We have our own front-end through which user will interact with the system. This includes creating bugs, adding comments, and doing various updates.

I want to be able to add users dynamically, which is possible through REST API in v5 (current stable). I cannot however add API key for a user dynamically. For now, I think doing the auth via loginid and password is the way to go. However, this is marked as "Will be removed in future", with recommended way for auth being the API key.

Can a superadmin, whose API key already exists, create users, and then create their API keys as well, all through REST APIs?
Thorsten Schöning
2018-07-08 11:51:41 UTC
Permalink
Post by b***@gmail.com
TL;DR Can API key for a user be created through REST API with credentials of superadmin?
I don't see a way as well, but with the help of extensions you are
able to create your own API-endpoint to create a user incl. an API-key
or only an API-key or whatever use-case you need in the end.

"object_end_of_create" is used during user creation in
Bugzilla::User::create.

https://www.bugzilla.org/docs/4.4/en/html/api/Bugzilla/Hook.html#object_end_of_create
https://www.bugzilla.org/docs/4.4/en/html/api/Bugzilla/Hook.html#webservice

https://bugzilla.readthedocs.io/en/5.0/integrating/extensions.html

https://www.bugzilla.org/docs/4.4/en/html/api/Bugzilla/Extension.html
https://www.bugzilla.org/docs/4.4/en/html/api/Bugzilla/Extension.html#Using_extensions%2Fcreate.pl
Post by b***@gmail.com
# Create a new API key if requested.
if ($cgi->param('new_key')) {
$vars->{new_key} = Bugzilla::User::APIKey->create({
user_id => $user->id,
description => scalar $cgi->param('new_description'),
});
# As a security precaution, we always sent out an e-mail when
# an API key is created
my $template = Bugzilla->template_inner($user->setting('lang'));
my $message;
$template->process('email/new-api-key.txt.tmpl', $vars, \$message)
|| ThrowTemplateError($template->error());
MessageToMTA($message);
}
Mit freundlichen Grüßen,

Thorsten Schöning
--
Thorsten Schöning E-Mail: ***@AM-SoFT.de
AM-SoFT IT-Systeme http://www.AM-SoFT.de/

Telefon...........05151- 9468- 55
Fax...............05151- 9468- 88
Mobil..............0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow
Loading...