Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
bugzilla
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
bugzilla
Commits
31651c97
Commit
31651c97
authored
Oct 12, 2016
by
David Lawrence
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug 1307003 - Add whoami endpoint
r=dylan
parent
ecc85459
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
173 additions
and
0 deletions
+173
-0
User.pm
Bugzilla/API/1_0/Resource/User.pm
+72
-0
User.pm
Bugzilla/WebService/User.pm
+66
-0
user.rst
docs/en/rst/api/core/v1/user.rst
+35
-0
No files found.
Bugzilla/API/1_0/Resource/User.pm
View file @
31651c97
...
@@ -40,6 +40,7 @@ use constant READ_ONLY => qw(
...
@@ -40,6 +40,7 @@ use constant READ_ONLY => qw(
login
login
logout
logout
valid_login
valid_login
whoami
)
;
)
;
use
constant
PUBLIC_METHODS
=>
qw(
use
constant
PUBLIC_METHODS
=>
qw(
...
@@ -50,6 +51,7 @@ use constant PUBLIC_METHODS => qw(
...
@@ -50,6 +51,7 @@ use constant PUBLIC_METHODS => qw(
offer_account_by_email
offer_account_by_email
update
update
valid_login
valid_login
whoami
)
;
)
;
use
constant
MAPPED_FIELDS
=>
{
use
constant
MAPPED_FIELDS
=>
{
...
@@ -106,6 +108,11 @@ sub REST_RESOURCES {
...
@@ -106,6 +108,11 @@ sub REST_RESOURCES {
return
{
$param
=>
[
$_
[
0
]
]
};
return
{
$param
=>
[
$_
[
0
]
]
};
}
}
}
}
},
qr{^/whoami$}
,
{
GET
=>
{
method
=>
'whoami'
}
}
}
];
];
return
$rest_resources
;
return
$rest_resources
;
...
@@ -479,6 +486,16 @@ sub _login_to_hash {
...
@@ -479,6 +486,16 @@ sub _login_to_hash {
return
$item
;
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
;
1
;
__END__
__END__
...
@@ -1155,6 +1172,61 @@ in Bugzilla B<4.4>.
...
@@ -1155,6 +1172,61 @@ 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
=head1 B<Methods in need of POD>
=head1 B<Methods in need of POD>
=over
=over
...
...
Bugzilla/WebService/User.pm
View file @
31651c97
...
@@ -40,6 +40,7 @@ use constant PUBLIC_METHODS => qw(
...
@@ -40,6 +40,7 @@ use constant PUBLIC_METHODS => qw(
offer_account_by_email
offer_account_by_email
update
update
valid_login
valid_login
whoami
)
;
)
;
use
constant
MAPPED_FIELDS
=>
{
use
constant
MAPPED_FIELDS
=>
{
...
@@ -428,6 +429,16 @@ sub _login_to_hash {
...
@@ -428,6 +429,16 @@ sub _login_to_hash {
return
$item
;
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
;
1
;
__END__
__END__
...
@@ -1130,3 +1141,58 @@ in Bugzilla B<4.4>.
...
@@ -1130,3 +1141,58 @@ in Bugzilla B<4.4>.
=back
=back
=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
docs/en/rst/api/core/v1/user.rst
View file @
31651c97
...
@@ -429,3 +429,38 @@ querying your own account, even if you are in the editusers group.
...
@@ -429,3 +429,38 @@ querying your own account, even if you are in the editusers group.
* 804 (Invalid Group Name)
* 804 (Invalid Group Name)
You passed a group name in the "groups" argument which either does not
You passed a group name in the "groups" argument which either does not
exist or you do not belong to it.
exist or you do not belong to it.
.. _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.
========== ====== =====================================================
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment