Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Tulir Asokan
mautrix-whatsapp
Commits
48d7ec69
Commit
48d7ec69
authored
Nov 24, 2020
by
Tulir Asokan
🐈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow browsers to authenticate in login websocket
parent
97407823
Pipeline
#1846
passed with stages
in 1 minute and 30 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
2 deletions
+18
-2
provisioning.go
provisioning.go
+18
-2
No files found.
provisioning.go
View file @
48d7ec69
...
...
@@ -53,7 +53,18 @@ func (prov *ProvisioningAPI) Init() {
func
(
prov
*
ProvisioningAPI
)
AuthMiddleware
(
h
http
.
Handler
)
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
auth
:=
r
.
Header
.
Get
(
"Authorization"
)
auth
=
auth
[
len
(
"Bearer "
)
:
]
if
len
(
auth
)
==
0
&&
strings
.
HasSuffix
(
r
.
URL
.
Path
,
"/login"
)
{
authParts
:=
strings
.
Split
(
r
.
Header
.
Get
(
"Sec-WebSocket-Protocol"
),
","
)
for
_
,
part
:=
range
authParts
{
part
=
strings
.
TrimSpace
(
part
)
if
strings
.
HasPrefix
(
part
,
"net.maunium.whatsapp.auth-"
)
{
auth
=
part
[
len
(
"net.maunium.whatsapp.auth-"
)
:
]
break
}
}
}
else
if
strings
.
HasPrefix
(
auth
,
"Bearer "
)
{
auth
=
auth
[
len
(
"Bearer "
)
:
]
}
if
auth
!=
prov
.
bridge
.
Config
.
AppService
.
Provisioning
.
SharedSecret
{
jsonResponse
(
w
,
http
.
StatusForbidden
,
map
[
string
]
interface
{}{
"error"
:
"Invalid auth token"
,
...
...
@@ -320,7 +331,12 @@ func (prov *ProvisioningAPI) Logout(w http.ResponseWriter, r *http.Request) {
jsonResponse
(
w
,
http
.
StatusOK
,
Response
{
true
,
"Logged out successfully."
})
}
var
upgrader
=
websocket
.
Upgrader
{}
var
upgrader
=
websocket
.
Upgrader
{
CheckOrigin
:
func
(
r
*
http
.
Request
)
bool
{
return
true
},
Subprotocols
:
[]
string
{
"net.maunium.whatsapp.login"
},
}
func
(
prov
*
ProvisioningAPI
)
Login
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
userID
:=
r
.
URL
.
Query
()
.
Get
(
"user_id"
)
...
...
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