diff options
author | David Lawrence <dkl@mozilla.com> | 2016-10-12 23:45:15 +0200 |
---|---|---|
committer | David Lawrence <dkl@mozilla.com> | 2016-10-12 23:45:15 +0200 |
commit | 31651c978e921e9e46cddd455f103fcf4b1a332a (patch) | |
tree | b88b472993fa3f99aeec128e8fccfd687173acc4 /Bugzilla | |
parent | ecc8545925a3c591bc6cbbfe0220e05eebe4e294 (diff) | |
download | bugzilla-31651c978e921e9e46cddd455f103fcf4b1a332a.tar.gz bugzilla-31651c978e921e9e46cddd455f103fcf4b1a332a.tar.xz |
Bug 1307003 - Add whoami endpoint
r=dylan
Diffstat (limited to 'Bugzilla')
-rw-r--r-- | Bugzilla/API/1_0/Resource/User.pm | 72 | ||||
-rw-r--r-- | Bugzilla/WebService/User.pm | 66 |
2 files changed, 138 insertions, 0 deletions
diff --git a/Bugzilla/API/1_0/Resource/User.pm b/Bugzilla/API/1_0/Resource/User.pm index 101a70529..e049f7f38 100644 --- a/Bugzilla/API/1_0/Resource/User.pm +++ b/Bugzilla/API/1_0/Resource/User.pm @@ -40,6 +40,7 @@ use constant READ_ONLY => qw( login logout valid_login + whoami ); use constant PUBLIC_METHODS => qw( @@ -50,6 +51,7 @@ use constant PUBLIC_METHODS => qw( offer_account_by_email update valid_login + whoami ); use constant MAPPED_FIELDS => { @@ -106,6 +108,11 @@ sub REST_RESOURCES { return { $param => [ $_[0] ] }; } } + }, + qr{^/whoami$}, { + GET => { + method => 'whoami' + } } ]; return $rest_resources; @@ -479,6 +486,16 @@ sub _login_to_hash { return $item; } +sub whoami { + my ($self, $params) = @_; + my $user = Bugzilla->login(LOGIN_REQUIRED); + return filter $params, { + id => as_int($user->id), + real_name => as_string($user->name), + name => as_login($user->login), + }; +} + 1; __END__ @@ -1155,6 +1172,61 @@ in Bugzilla B<4.4>. =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 + =head1 B<Methods in need of POD> =over diff --git a/Bugzilla/WebService/User.pm b/Bugzilla/WebService/User.pm index d69df5056..602e7e2cc 100644 --- a/Bugzilla/WebService/User.pm +++ b/Bugzilla/WebService/User.pm @@ -40,6 +40,7 @@ use constant PUBLIC_METHODS => qw( offer_account_by_email update valid_login + whoami ); use constant MAPPED_FIELDS => { @@ -428,6 +429,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__ @@ -1130,3 +1141,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 |