Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pleroma
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
NEETzsche
pleroma
Commits
7aa53d52
Commit
7aa53d52
authored
6 years ago
by
Eugenij
Browse files
Options
Downloads
Patches
Plain Diff
Return 403 on oauth token exchange for a deactivated user
parent
e3ca9f70
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/pleroma/web/oauth/oauth_controller.ex
+6
-0
6 additions, 0 deletions
lib/pleroma/web/oauth/oauth_controller.ex
test/web/oauth/oauth_controller_test.exs
+26
-0
26 additions, 0 deletions
test/web/oauth/oauth_controller_test.exs
with
32 additions
and
0 deletions
lib/pleroma/web/oauth/oauth_controller.ex
+
6
−
0
View file @
7aa53d52
...
...
@@ -152,6 +152,7 @@ def token_exchange(
with
{
_
,
{
:ok
,
%
User
{}
=
user
}}
<-
{
:get_user
,
Authenticator
.
get_user
(
conn
)},
%
App
{}
=
app
<-
get_app_from_request
(
conn
,
params
),
{
:auth_active
,
true
}
<-
{
:auth_active
,
User
.
auth_active?
(
user
)},
{
:user_active
,
true
}
<-
{
:user_active
,
!user
.
info
.
deactivated
},
scopes
<-
oauth_scopes
(
params
,
app
.
scopes
),
[]
<-
scopes
--
app
.
scopes
,
true
<-
Enum
.
any?
(
scopes
),
...
...
@@ -175,6 +176,11 @@ def token_exchange(
|>
put_status
(
:forbidden
)
|>
json
(%{
error:
"Your login is missing a confirmed e-mail address"
})
{
:user_active
,
false
}
->
conn
|>
put_status
(
:forbidden
)
|>
json
(%{
error:
"Your account is currently disabled"
})
_error
->
put_status
(
conn
,
400
)
|>
json
(%{
error:
"Invalid credentials"
})
...
...
This diff is collapsed.
Click to expand it.
test/web/oauth/oauth_controller_test.exs
+
26
−
0
View file @
7aa53d52
...
...
@@ -327,6 +327,32 @@ test "rejects token exchange for valid credentials belonging to unconfirmed user
refute
Map
.
has_key?
(
resp
,
"access_token"
)
end
test
"rejects token exchange for valid credentials belonging to deactivated user"
do
password
=
"testpassword"
user
=
insert
(
:user
,
password_hash:
Comeonin
.
Pbkdf2
.
hashpwsalt
(
password
),
info:
%{
deactivated:
true
}
)
app
=
insert
(
:oauth_app
)
conn
=
build_conn
()
|>
post
(
"/oauth/token"
,
%{
"grant_type"
=>
"password"
,
"username"
=>
user
.
nickname
,
"password"
=>
password
,
"client_id"
=>
app
.
client_id
,
"client_secret"
=>
app
.
client_secret
})
assert
resp
=
json_response
(
conn
,
403
)
assert
%{
"error"
=>
_
}
=
resp
refute
Map
.
has_key?
(
resp
,
"access_token"
)
end
test
"rejects an invalid authorization code"
do
app
=
insert
(
:oauth_app
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment