diff options
author | David Lawrence <dkl@mozilla.com> | 2015-09-24 16:47:18 +0200 |
---|---|---|
committer | David Lawrence <dkl@mozilla.com> | 2015-09-24 16:47:53 +0200 |
commit | 923afd71d4bf1c0854deae96d3af7fd6d268646e (patch) | |
tree | 883bb776040b0c8ae3b98b83efaeee0fba4561a4 /Bugzilla/WebService | |
parent | 89e65535c55fb20c916e2ed9492aaae265f5c5de (diff) | |
download | bugzilla-923afd71d4bf1c0854deae96d3af7fd6d268646e.tar.gz bugzilla-923afd71d4bf1c0854deae96d3af7fd6d268646e.tar.xz |
Bug 1204683: Add whoami endpoint
Diffstat (limited to 'Bugzilla/WebService')
-rw-r--r-- | Bugzilla/WebService/Server/REST/Resources/User.pm | 5 | ||||
-rw-r--r-- | Bugzilla/WebService/User.pm | 66 |
2 files changed, 71 insertions, 0 deletions
diff --git a/Bugzilla/WebService/Server/REST/Resources/User.pm b/Bugzilla/WebService/Server/REST/Resources/User.pm index b9ecc21ba..7d494064d 100644 --- a/Bugzilla/WebService/Server/REST/Resources/User.pm +++ b/Bugzilla/WebService/Server/REST/Resources/User.pm @@ -67,6 +67,11 @@ sub _rest_resources { } }, }, + qr{^/whoami$}, { + GET => { + method => 'whoami' + } + } ]; return $rest_resources; } diff --git a/Bugzilla/WebService/User.pm b/Bugzilla/WebService/User.pm index 2d3f5f185..5812fbed2 100644 --- a/Bugzilla/WebService/User.pm +++ b/Bugzilla/WebService/User.pm @@ -52,6 +52,7 @@ use constant PUBLIC_METHODS => qw( offer_account_by_email update valid_login + whoami ); use constant MAPPED_FIELDS => { @@ -430,6 +431,16 @@ sub mfa_enroll { return $provider->enroll(); } +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__ @@ -1084,3 +1095,58 @@ illegal to pass a group name you don't belong to. =item REST API call added in Bugzilla B<5.0>. =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 |