Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
go-sso
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
Model registry
Operate
Environments
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
go-sso
Commits
9e4b95f8
Commit
9e4b95f8
authored
6 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Fix some lint warnings using 'nolint' instead of weird idioms
parent
57f0955d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/http.go
+13
-9
13 additions, 9 deletions
server/http.go
server/login.go
+6
-2
6 additions, 2 deletions
server/login.go
with
19 additions
and
11 deletions
server/http.go
+
13
−
9
View file @
9e4b95f8
...
@@ -161,7 +161,7 @@ func (h *Server) loginCallback(w http.ResponseWriter, req *http.Request, usernam
...
@@ -161,7 +161,7 @@ func (h *Server) loginCallback(w http.ResponseWriter, req *http.Request, usernam
// Create cookie-based session for the authenticated user.
// Create cookie-based session for the authenticated user.
session
:=
newAuthSession
(
h
.
authSessionLifetime
,
username
,
userinfo
)
session
:=
newAuthSession
(
h
.
authSessionLifetime
,
username
,
userinfo
)
httpSession
,
_
:=
h
.
authSessionStore
.
Get
(
req
,
authSessionKey
)
httpSession
,
_
:=
h
.
authSessionStore
.
Get
(
req
,
authSessionKey
)
// nolint
httpSession
.
Values
[
"auth"
]
=
session
httpSession
.
Values
[
"auth"
]
=
session
return
httpSession
.
Save
(
req
,
w
)
return
httpSession
.
Save
(
req
,
w
)
}
}
...
@@ -179,7 +179,9 @@ func (h *Server) withAuth(f func(http.ResponseWriter, *http.Request, *authSessio
...
@@ -179,7 +179,9 @@ func (h *Server) withAuth(f func(http.ResponseWriter, *http.Request, *authSessio
return
return
}
}
httpSession
.
Options
.
MaxAge
=
-
1
httpSession
.
Options
.
MaxAge
=
-
1
_
=
httpSession
.
Save
(
req
,
w
)
if
err
:=
httpSession
.
Save
(
req
,
w
);
err
!=
nil
{
log
.
Printf
(
"error saving session: %v"
,
err
)
}
http
.
Redirect
(
w
,
req
,
makeLoginURL
(
req
),
http
.
StatusFound
)
http
.
Redirect
(
w
,
req
,
makeLoginURL
(
req
),
http
.
StatusFound
)
})
})
}
}
...
@@ -227,7 +229,9 @@ func (h *Server) handleHomepage(w http.ResponseWriter, req *http.Request, sessio
...
@@ -227,7 +229,9 @@ func (h *Server) handleHomepage(w http.ResponseWriter, req *http.Request, sessio
}
}
session
.
AddService
(
service
)
session
.
AddService
(
service
)
_
=
sessions
.
Save
(
req
,
w
)
if
err
:=
sessions
.
Save
(
req
,
w
);
err
!=
nil
{
log
.
Printf
(
"error saving session: %v"
,
err
)
}
// Redirect to service callback.
// Redirect to service callback.
callbackURL
:=
serviceLoginCallback
(
service
,
destination
,
token
)
callbackURL
:=
serviceLoginCallback
(
service
,
destination
,
token
)
...
@@ -256,13 +260,13 @@ func (h *Server) handleLogout(w http.ResponseWriter, req *http.Request, session
...
@@ -256,13 +260,13 @@ func (h *Server) handleLogout(w http.ResponseWriter, req *http.Request, session
if
req
.
Method
==
"POST"
{
if
req
.
Method
==
"POST"
{
data
[
"IsPOST"
]
=
true
data
[
"IsPOST"
]
=
true
data
[
"IncludeLogoutScripts"
]
=
true
data
[
"IncludeLogoutScripts"
]
=
true
svcJSON
,
_
:=
json
.
Marshal
(
svcs
)
svcJSON
,
_
:=
json
.
Marshal
(
svcs
)
// nolint
data
[
"ServicesJSON"
]
=
string
(
svcJSON
)
data
[
"ServicesJSON"
]
=
string
(
svcJSON
)
// Clear the local session.
// Clear the local session.
Ignore errors.
httpSession
,
_
:=
h
.
authSessionStore
.
Get
(
req
,
authSessionKey
)
httpSession
,
_
:=
h
.
authSessionStore
.
Get
(
req
,
authSessionKey
)
// nolint
httpSession
.
Options
.
MaxAge
=
-
1
httpSession
.
Options
.
MaxAge
=
-
1
_
=
httpSession
.
Save
(
req
,
w
)
httpSession
.
Save
(
req
,
w
)
// nolint
// Close the keystore.
// Close the keystore.
if
h
.
keystore
!=
nil
{
if
h
.
keystore
!=
nil
{
...
@@ -278,7 +282,7 @@ func (h *Server) handleLogout(w http.ResponseWriter, req *http.Request, session
...
@@ -278,7 +282,7 @@ func (h *Server) handleLogout(w http.ResponseWriter, req *http.Request, session
w
.
Header
()
.
Set
(
"Content-Security-Policy"
,
logoutContentSecurityPolicy
)
w
.
Header
()
.
Set
(
"Content-Security-Policy"
,
logoutContentSecurityPolicy
)
}
}
h
.
tpl
.
ExecuteTemplate
(
w
,
"logout.html"
,
data
)
h
.
tpl
.
ExecuteTemplate
(
w
,
"logout.html"
,
data
)
// nolint
}
}
func
(
h
*
Server
)
handleExchange
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
func
(
h
*
Server
)
handleExchange
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
...
@@ -301,7 +305,7 @@ func (h *Server) handleExchange(w http.ResponseWriter, req *http.Request) {
...
@@ -301,7 +305,7 @@ func (h *Server) handleExchange(w http.ResponseWriter, req *http.Request) {
}
}
w
.
Header
()
.
Set
(
"Content-Type"
,
"text/plain"
)
w
.
Header
()
.
Set
(
"Content-Type"
,
"text/plain"
)
_
,
_
=
io
.
WriteString
(
w
,
token
)
io
.
WriteString
(
w
,
token
)
// nolint
}
}
// Handler returns the http.Handler for the SSO server application.
// Handler returns the http.Handler for the SSO server application.
...
...
This diff is collapsed.
Click to expand it.
server/login.go
+
6
−
2
View file @
9e4b95f8
...
@@ -131,7 +131,11 @@ func (l *loginHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
...
@@ -131,7 +131,11 @@ func (l *loginHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
case
loginStateSuccess
:
case
loginStateSuccess
:
// Successful login. Delete the login session.
// Successful login. Delete the login session.
httpSession
.
Options
.
MaxAge
=
-
1
httpSession
.
Options
.
MaxAge
=
-
1
_
=
httpSession
.
Save
(
req
,
w
)
if
err
:=
httpSession
.
Save
(
req
,
w
);
err
!=
nil
{
log
.
Printf
(
"login error saving session: %v"
,
err
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
if
err
:=
l
.
loginCallback
(
w
,
req
,
session
.
Username
,
session
.
Password
,
session
.
UserInfo
);
err
!=
nil
{
if
err
:=
l
.
loginCallback
(
w
,
req
,
session
.
Username
,
session
.
Password
,
session
.
UserInfo
);
err
!=
nil
{
log
.
Printf
(
"login callback error: %v: user=%s"
,
err
,
session
.
Username
)
log
.
Printf
(
"login callback error: %v: user=%s"
,
err
,
session
.
Username
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
...
@@ -146,7 +150,7 @@ func (l *loginHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
...
@@ -146,7 +150,7 @@ func (l *loginHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
return
}
}
_
,
_
=
w
.
Write
(
body
)
w
.
Write
(
body
)
// nolint
return
return
default
:
default
:
...
...
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