Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
auth-server-http-proxy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
id
auth-server-http-proxy
Commits
010f9121
Commit
010f9121
authored
3 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Simplify the http handler by using global options
parent
6fb53587
No related branches found
No related tags found
1 merge request
!1
Simplify the http handler by using global options
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
go.sum
+1
-0
1 addition, 0 deletions
go.sum
main.go
+35
-40
35 additions, 40 deletions
main.go
with
36 additions
and
40 deletions
go.sum
+
1
−
0
View file @
010f9121
...
@@ -85,6 +85,7 @@ github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dR
...
@@ -85,6 +85,7 @@ github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dR
github.com/boombuler/barcode
v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:
paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/boombuler/barcode
v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:
paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/bradfitz/gomemcache
v0.0.0-20220106215444-fb4bf637b56d/go.mod h1:
H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
github.com/bradfitz/gomemcache
v0.0.0-20220106215444-fb4bf637b56d/go.mod h1:
H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
github.com/casbin/casbin/v2
v2.1.2/go.mod h1:
YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
github.com/casbin/casbin/v2
v2.1.2/go.mod h1:
YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
github.com/cenkalti/backoff
v2.2.1+incompatible h1:
tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
github.com/cenkalti/backoff
v2.2.1+incompatible/go.mod h1:
90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/cenkalti/backoff
v2.2.1+incompatible/go.mod h1:
90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/cenkalti/backoff/v4
v4.0.2/go.mod h1:
eEew/i+1Q6OrCDZh3WiXYv3+nJwBASZ8Bog/87DQnVg=
github.com/cenkalti/backoff/v4
v4.0.2/go.mod h1:
eEew/i+1Q6OrCDZh3WiXYv3+nJwBASZ8Bog/87DQnVg=
github.com/cenkalti/backoff/v4
v4.1.0/go.mod h1:
scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
github.com/cenkalti/backoff/v4
v4.1.0/go.mod h1:
scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
...
...
This diff is collapsed.
Click to expand it.
main.go
+
35
−
40
View file @
010f9121
...
@@ -11,21 +11,18 @@ import (
...
@@ -11,21 +11,18 @@ import (
"git.autistici.org/id/auth/client"
"git.autistici.org/id/auth/client"
)
)
const
defaultPort
=
4041
var
(
port
=
flag
.
Int
(
"port"
,
4041
,
"A port to bind to on the specified addresses"
)
service
=
flag
.
String
(
"service"
,
"xmpp"
,
"Service to use for authentication"
)
)
func
main
()
{
func
main
()
{
var
port
=
flag
.
Int
(
"port"
,
defaultPort
,
"A port to bind to on the specified addresses"
)
flag
.
Parse
()
flag
.
Parse
()
if
flag
.
NArg
()
!=
1
{
http
.
HandleFunc
(
"/"
,
authHandlerFunc
)
log
.
Fatal
(
"Expected exactly one service name"
)
}
service
:=
flag
.
Args
()[
0
]
log
.
Fatal
(
http
.
ListenAndServe
(
log
.
Fatal
(
http
.
ListenAndServe
(
fmt
.
Sprintf
(
"127.0.0.1:%d"
,
*
port
),
fmt
.
Sprintf
(
"127.0.0.1:%d"
,
*
port
),
http
.
HandlerFunc
(
authHandlerFunc
(
service
))
))
nil
))
}
}
type
authPayload
struct
{
type
authPayload
struct
{
...
@@ -33,8 +30,7 @@ type authPayload struct {
...
@@ -33,8 +30,7 @@ type authPayload struct {
Pass
string
`json:"password"`
Pass
string
`json:"password"`
}
}
func
authHandlerFunc
(
service
string
)
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
authHandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
var
p
authPayload
var
p
authPayload
err
:=
json
.
NewDecoder
(
r
.
Body
)
.
Decode
(
&
p
)
err
:=
json
.
NewDecoder
(
r
.
Body
)
.
Decode
(
&
p
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -45,7 +41,7 @@ func authHandlerFunc(service string) func(w http.ResponseWriter, r *http.Request
...
@@ -45,7 +41,7 @@ func authHandlerFunc(service string) func(w http.ResponseWriter, r *http.Request
c
:=
client
.
New
(
client
.
DefaultSocketPath
)
c
:=
client
.
New
(
client
.
DefaultSocketPath
)
resp
,
err
:=
c
.
Authenticate
(
r
.
Context
(),
&
auth
.
Request
{
resp
,
err
:=
c
.
Authenticate
(
r
.
Context
(),
&
auth
.
Request
{
Service
:
service
,
Service
:
*
service
,
Username
:
p
.
User
,
Username
:
p
.
User
,
Password
:
[]
byte
(
p
.
Pass
),
Password
:
[]
byte
(
p
.
Pass
),
})
})
...
@@ -66,4 +62,3 @@ func authHandlerFunc(service string) func(w http.ResponseWriter, r *http.Request
...
@@ -66,4 +62,3 @@ func authHandlerFunc(service string) func(w http.ResponseWriter, r *http.Request
return
return
}
}
}
}
}
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