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
07c9a990
Commit
07c9a990
authored
6 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Redirect the user to a configurable URL when accessing homepage by mistake
Fixes issue
#6
.
parent
b1c0a012
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/config.go
+11
-13
11 additions, 13 deletions
server/config.go
server/http.go
+15
-0
15 additions, 0 deletions
server/http.go
with
26 additions
and
13 deletions
server/config.go
+
11
−
13
View file @
07c9a990
...
...
@@ -36,6 +36,7 @@ type Config struct {
AuthService
string
`yaml:"auth_service"`
U2FAppID
string
`yaml:"u2f_app_id"`
URLPrefix
string
`yaml:"url_path_prefix"`
HomepageRedirectURL
string
`yaml:"homepage_redirect_url"`
DeviceManager
*
device
.
Config
`yaml:"device_manager"`
KeyStore
*
clientutil
.
BackendConfig
`yaml:"keystore"`
KeyStoreEnableGroups
[]
string
`yaml:"keystore_enable_groups"`
...
...
@@ -45,26 +46,23 @@ type Config struct {
}
// Check syntax (missing required values).
//
// nolint: gocyclo
func
(
c
*
Config
)
valid
()
error
{
if
c
.
SecretKeyFile
==
""
{
switch
{
case
c
.
SecretKeyFile
==
""
:
return
errors
.
New
(
"secret_key_file is empty"
)
}
if
c
.
PublicKeyFile
==
""
{
case
c
.
PublicKeyFile
==
""
:
return
errors
.
New
(
"public_key_file is empty"
)
}
if
c
.
Domain
==
""
{
case
c
.
Domain
==
""
:
return
errors
.
New
(
"domain is empty"
)
}
if
len
(
c
.
AllowedServices
)
==
0
{
case
len
(
c
.
AllowedServices
)
==
0
:
return
errors
.
New
(
"the list of allowed services is empty"
)
}
if
c
.
AuthService
==
""
{
case
c
.
AuthService
==
""
:
return
errors
.
New
(
"auth_service is empty"
)
}
if
c
.
U2FAppID
!=
""
&&
!
strings
.
HasPrefix
(
c
.
U2FAppID
,
"https://"
)
{
case
c
.
U2FAppID
!=
""
&&
!
strings
.
HasPrefix
(
c
.
U2FAppID
,
"https://"
)
:
return
errors
.
New
(
"u2f_app_id does not start with https://"
)
}
if
c
.
URLPrefix
!=
""
&&
!
strings
.
HasPrefix
(
c
.
URLPrefix
,
"/"
)
{
case
c
.
URLPrefix
!=
""
&&
!
strings
.
HasPrefix
(
c
.
URLPrefix
,
"/"
)
:
return
errors
.
New
(
"url_path_prefix does not start with /"
)
}
...
...
This diff is collapsed.
Click to expand it.
server/http.go
+
15
−
0
View file @
07c9a990
...
...
@@ -93,6 +93,7 @@ type Server struct {
csrfSecret
[]
byte
tpl
*
template
.
Template
urlPrefix
string
homepageRedirectURL
string
}
func
sl2bl
(
sl
[]
string
)
[][]
byte
{
...
...
@@ -120,6 +121,7 @@ func New(loginService *LoginService, authClient authclient.Client, config *Confi
authSessionStore
:
store
,
loginService
:
loginService
,
urlPrefix
:
urlPrefix
,
homepageRedirectURL
:
config
.
HomepageRedirectURL
,
tpl
:
parseEmbeddedTemplates
(),
}
if
config
.
CSRFSecret
!=
""
{
...
...
@@ -252,6 +254,19 @@ func (h *Server) handleHomepage(w http.ResponseWriter, req *http.Request, sessio
}
}
// If the above parameters are unset, we're probably faced with a user
// that reached this URL by other means. Redirect them to the
// configured homepageRedirectURL, or at least return a slightly more
// user-friendly error.
if
service
==
""
||
destination
==
""
{
if
h
.
homepageRedirectURL
!=
""
{
http
.
Redirect
(
w
,
req
,
h
.
homepageRedirectURL
,
http
.
StatusFound
)
}
else
{
http
.
Error
(
w
,
"You are not supposed to reach this page directly. Use the back button in your browser instead."
,
http
.
StatusBadRequest
)
}
return
}
// Make the authorization request.
token
,
err
:=
h
.
loginService
.
Authorize
(
username
,
service
,
destination
,
nonce
,
groups
)
if
err
!=
nil
{
...
...
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