Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
9aafe77e
Commit
9aafe77e
authored
Sep 20, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
I want be able to get token via api. Used for mobile applications
parent
37817cc3
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
90 additions
and
2 deletions
+90
-2
doc/api/README.md
doc/api/README.md
+1
-0
doc/api/session.md
doc/api/session.md
+22
-0
lib/api.rb
lib/api.rb
+1
-0
lib/api/entities.rb
lib/api/entities.rb
+6
-2
lib/api/session.rb
lib/api/session.rb
+21
-0
spec/requests/api/session_spec.rb
spec/requests/api/session_spec.rb
+39
-0
No files found.
doc/api/README.md
View file @
9aafe77e
...
...
@@ -30,6 +30,7 @@ When listing resources you can pass the following parameters:
## Contents
+
[
Users
](
https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/users.md
)
+
[
Session
](
https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/session.md
)
+
[
Projects
](
https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/projects.md
)
+
[
Snippets
](
https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/snippets.md
)
+
[
Issues
](
https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/issues.md
)
...
...
doc/api/session.md
0 → 100644
View file @
9aafe77e
Login to get private token
```
POST /session
```
Parameters:
+
`email`
(required) - The email of user
+
`password`
(required) - Valid password
```
json
{
"id"
:
1
,
"email"
:
"john@example.com"
,
"name"
:
"John Smith"
,
"private_token"
:
"dd34asd13as"
,
"created_at"
:
"2012-05-23T08:00:58Z"
,
"blocked"
:
true
}
```
lib/api.rb
View file @
9aafe77e
...
...
@@ -18,5 +18,6 @@ module Gitlab
mount
Issues
mount
Milestones
mount
Keys
mount
Session
end
end
lib/api/entities.rb
View file @
9aafe77e
...
...
@@ -9,6 +9,10 @@ module Gitlab
expose
:id
,
:email
,
:name
,
:blocked
,
:created_at
end
class
UserLogin
<
Grape
::
Entity
expose
:id
,
:email
,
:name
,
:private_token
,
:blocked
,
:created_at
end
class
Hook
<
Grape
::
Entity
expose
:id
,
:url
end
...
...
@@ -52,8 +56,8 @@ module Gitlab
end
class
Key
<
Grape
::
Entity
expose
:id
,
:title
,
expose
:id
,
:title
,
:key
end
end
...
...
lib/api/session.rb
0 → 100644
View file @
9aafe77e
module
Gitlab
# Users API
class
Session
<
Grape
::
API
# Login to get token
#
# Example Request:
# POST /session
post
"/session"
do
resource
=
User
.
find_for_database_authentication
(
email:
params
[
:email
])
return
forbidden!
unless
resource
if
resource
.
valid_password?
(
params
[
:password
])
present
resource
,
with:
Entities
::
UserLogin
else
forbidden!
end
end
end
end
spec/requests/api/session_spec.rb
0 → 100644
View file @
9aafe77e
require
'spec_helper'
describe
Gitlab
::
API
do
include
ApiHelpers
let
(
:user
)
{
Factory
:user
}
describe
"POST /session"
do
context
"when valid password"
do
it
"should return private token"
do
post
api
(
"/session"
),
email:
user
.
email
,
password:
'123456'
response
.
status
.
should
==
201
json_response
[
'email'
].
should
==
user
.
email
json_response
[
'private_token'
].
should
==
user
.
private_token
end
end
context
"when invalid password"
do
it
"should return authentication error"
do
post
api
(
"/session"
),
email:
user
.
email
,
password:
'123'
response
.
status
.
should
==
403
json_response
[
'email'
].
should
be_nil
json_response
[
'private_token'
].
should
be_nil
end
end
context
"when empty password"
do
it
"should return authentication error"
do
post
api
(
"/session"
),
email:
user
.
email
response
.
status
.
should
==
403
json_response
[
'email'
].
should
be_nil
json_response
[
'private_token'
].
should
be_nil
end
end
end
end
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