aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lawrence <dkl@mozilla.com>2016-10-12 21:45:15 +0000
committerMichał Górny <mgorny@gentoo.org>2020-03-30 21:12:09 +0200
commitec0193eb43cec46cf0b4812b9833acdbf53cfe3f (patch)
tree2b9a40974f23dc17e94009af7c39898004d10a54
parentremove SuperH from CC (diff)
downloadbugzilla-ec0193eb43cec46cf0b4812b9833acdbf53cfe3f.tar.gz
bugzilla-ec0193eb43cec46cf0b4812b9833acdbf53cfe3f.tar.bz2
bugzilla-ec0193eb43cec46cf0b4812b9833acdbf53cfe3f.zip
Bug 1307003 - Add whoami endpointgentoo-5.0.6.3
r=dylan (cherry picked from commit 31651c978e921e9e46cddd455f103fcf4b1a332a) (rebased for 5.0 by mgorny) Signed-off-by: Michał Górny <mgorny@gentoo.org>
-rw-r--r--Bugzilla/WebService/Server/REST/Resources/User.pm6
-rw-r--r--Bugzilla/WebService/User.pm67
-rw-r--r--docs/en/rst/api/core/v1/user.rst35
3 files changed, 107 insertions, 1 deletions
diff --git a/Bugzilla/WebService/Server/REST/Resources/User.pm b/Bugzilla/WebService/Server/REST/Resources/User.pm
index 4555b4dbc..d7bd3acd4 100644
--- a/Bugzilla/WebService/Server/REST/Resources/User.pm
+++ b/Bugzilla/WebService/Server/REST/Resources/User.pm
@@ -47,7 +47,11 @@ sub _rest_resources {
return {$param => [$_[0]]};
}
}
- }
+ },
+ qr{^/whoami$},
+ {
+ GET => {method => 'whoami'}
+ },
];
return $rest_resources;
}
diff --git a/Bugzilla/WebService/User.pm b/Bugzilla/WebService/User.pm
index 3fcc929ce..cdfe5b3ad 100644
--- a/Bugzilla/WebService/User.pm
+++ b/Bugzilla/WebService/User.pm
@@ -28,6 +28,7 @@ use constant LOGIN_EXEMPT => {login => 1, offer_account_by_email => 1,};
use constant READ_ONLY => qw(
get
+ whoami
);
use constant PUBLIC_METHODS => qw(
@@ -38,6 +39,7 @@ use constant PUBLIC_METHODS => qw(
offer_account_by_email
update
valid_login
+ whoami
);
use constant MAPPED_FIELDS =>
@@ -416,6 +418,16 @@ sub _login_to_hash {
return $item;
}
+sub whoami {
+ my ($self, $params) = @_;
+ my $user = Bugzilla->login(LOGIN_REQUIRED);
+ return filter $params, {
+ id => $self->type('int', $user->id),
+ real_name => $self->type('string', $user->name),
+ name => $self->type('email', $user->login),
+ };
+}
+
1;
__END__
@@ -1102,3 +1114,58 @@ in Bugzilla B<4.4>.
=back
=back
+
+=head2 whoami
+
+=over
+
+=item B<Description>
+
+Allows for validating a user's API key, token, or username and password.
+If sucessfully authenticated, it returns simple information about the
+logged in user.
+
+=item B<Params> (none)
+
+=item B<Returns>
+
+On success, a hash containing information about the logged in user.
+
+=over
+
+=item id
+
+C<int> The unique integer ID that Bugzilla uses to represent this user.
+Even if the user's login name changes, this will not change.
+
+=item real_name
+
+C<string> The actual name of the user. May be blank.
+
+=item name
+
+C<string> The login name of the user.
+
+=back
+
+=item B<Errors>
+
+=over
+
+=item 300 (Invalid Username or Password)
+
+The username does not exist, or the password is wrong.
+
+=item 301 (Account Disabled)
+
+The account has been disabled. A reason may be specified with the
+error.
+
+=item 305 (New Password Required)
+
+The current password is correct, but the user is asked to change
+his password.
+
+=back
+
+=back
diff --git a/docs/en/rst/api/core/v1/user.rst b/docs/en/rst/api/core/v1/user.rst
index e27211a7f..7f835cc8a 100644
--- a/docs/en/rst/api/core/v1/user.rst
+++ b/docs/en/rst/api/core/v1/user.rst
@@ -378,3 +378,38 @@ and not in 'editusers' group, you will only be returned the ``id``, ``name``,
returned are filtered based on your permission to bless each group. The
``saved_searches`` and ``saved_reports`` items are only returned if you are
querying your own account, even if you are in the editusers group.
+
+.. _rest_user_whoami:
+
+Who Am I
+--------
+
+Allows for validating a user's API key, token, or username and password.
+If sucessfully authenticated, it returns simple information about the
+logged in user.
+
+**Request**
+
+.. code-block:: text
+
+ GET /rest/whoami
+
+**Response**
+
+.. code-block:: js
+
+ {
+ "id" : "1234",
+ "name" : "user@bugzulla.org",
+ "real_name" : "Test User",
+ }
+
+========== ====== =====================================================
+name type description
+========== ====== =====================================================
+id int The unique integer ID that Bugzilla uses to represent
+ this user. Even if the user's login name changes,
+ this will not change.
+real_name string The actual name of the user. May be blank.
+name string string The login name of the user.
+========== ====== =====================================================