Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
6910fb37
Commit
6910fb37
authored
Apr 01, 2019
by
Ivan Tashkinov
Browse files
Fixed local MastoFE authentication / `force_login` option.
parent
cbe09d94
Changes
3
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/controller_helper.ex
View file @
6910fb37
...
@@ -7,7 +7,7 @@ defmodule Pleroma.Web.ControllerHelper do
...
@@ -7,7 +7,7 @@ defmodule Pleroma.Web.ControllerHelper do
# As in MastoAPI, per https://api.rubyonrails.org/classes/ActiveModel/Type/Boolean.html
# As in MastoAPI, per https://api.rubyonrails.org/classes/ActiveModel/Type/Boolean.html
@falsy_param_values
[
false
,
0
,
"0"
,
"f"
,
"F"
,
"false"
,
"FALSE"
,
"off"
,
"OFF"
]
@falsy_param_values
[
false
,
0
,
"0"
,
"f"
,
"F"
,
"false"
,
"FALSE"
,
"off"
,
"OFF"
]
def
truthy_param?
(
nil
)
,
do
:
nil
def
truthy_param?
(
blank_value
)
when
blank_value
in
[
nil
,
""
]
,
do
:
nil
def
truthy_param?
(
value
),
do
:
value
not
in
@falsy_param_values
def
truthy_param?
(
value
),
do
:
value
not
in
@falsy_param_values
def
oauth_scopes
(
params
,
default
)
do
def
oauth_scopes
(
params
,
default
)
do
...
...
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
View file @
6910fb37
...
@@ -1249,16 +1249,22 @@ defp get_user_flavour(_) do
...
@@ -1249,16 +1249,22 @@ defp get_user_flavour(_) do
"glitch"
"glitch"
end
end
def
login
(
conn
,
%{
"code"
=>
code
})
do
def
login
(%{
assigns:
%{
user:
%
User
{}}}
=
conn
,
_params
)
do
redirect
(
conn
,
to:
local_mastodon_root_path
(
conn
))
end
@doc
"Local Mastodon FE login init action"
def
login
(
conn
,
%{
"code"
=>
auth_token
})
do
with
{
:ok
,
app
}
<-
get_or_make_app
(),
with
{
:ok
,
app
}
<-
get_or_make_app
(),
%
Authorization
{}
=
auth
<-
Repo
.
get_by
(
Authorization
,
token:
code
,
app_id:
app
.
id
),
%
Authorization
{}
=
auth
<-
Repo
.
get_by
(
Authorization
,
token:
auth_token
,
app_id:
app
.
id
),
{
:ok
,
token
}
<-
Token
.
exchange_token
(
app
,
auth
)
do
{
:ok
,
token
}
<-
Token
.
exchange_token
(
app
,
auth
)
do
conn
conn
|>
put_session
(
:oauth_token
,
token
.
token
)
|>
put_session
(
:oauth_token
,
token
.
token
)
|>
redirect
(
to:
"/web/getting-started"
)
|>
redirect
(
to:
local_mastodon_root_path
(
conn
)
)
end
end
end
end
@doc
"Local Mastodon FE callback action"
def
login
(
conn
,
_
)
do
def
login
(
conn
,
_
)
do
with
{
:ok
,
app
}
<-
get_or_make_app
()
do
with
{
:ok
,
app
}
<-
get_or_make_app
()
do
path
=
path
=
...
@@ -1276,6 +1282,8 @@ def login(conn, _) do
...
@@ -1276,6 +1282,8 @@ def login(conn, _) do
end
end
end
end
defp
local_mastodon_root_path
(
conn
),
do
:
mastodon_api_path
(
conn
,
:index
,
[
"getting-started"
])
defp
get_or_make_app
do
defp
get_or_make_app
do
find_attrs
=
%{
client_name:
@local_mastodon_name
,
redirect_uris:
"."
}
find_attrs
=
%{
client_name:
@local_mastodon_name
,
redirect_uris:
"."
}
scopes
=
[
"read"
,
"write"
,
"follow"
,
"push"
]
scopes
=
[
"read"
,
"write"
,
"follow"
,
"push"
]
...
...
lib/pleroma/web/oauth/oauth_controller.ex
View file @
6910fb37
...
@@ -239,7 +239,7 @@ defp get_app_from_request(conn, params) do
...
@@ -239,7 +239,7 @@ defp get_app_from_request(conn, params) do
end
end
# Special case: Local MastodonFE
# Special case: Local MastodonFE
defp
redirect_uri
(
conn
,
"."
),
do
:
mastodon_api_url
(
conn
,
:
index
,
[]
)
defp
redirect_uri
(
conn
,
"."
),
do
:
mastodon_api_url
(
conn
,
:
login
)
defp
redirect_uri
(
_conn
,
redirect_uri
),
do
:
redirect_uri
defp
redirect_uri
(
_conn
,
redirect_uri
),
do
:
redirect_uri
end
end
Write
Preview
Supports
Markdown
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