mirror of
https://github.com/janishutz/oidclogin.git
synced 2026-10-08 17:26:20 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6b8422a1e | ||
|
|
6cb582a762 | ||
|
|
e241d90f42 | ||
|
|
59f635f01e |
No files matched your search
@@ -128,6 +128,15 @@ func logoutHandler(c *gin.Context) {
|
|||||||
session := sessions.Default(c)
|
session := sessions.Default(c)
|
||||||
session.Clear()
|
session.Clear()
|
||||||
session.Save()
|
session.Save()
|
||||||
|
redir := ""
|
||||||
|
if c.Query("returnTo") != "" {
|
||||||
|
redir = c.Query("returnTo")
|
||||||
|
}
|
||||||
|
if redir != "" {
|
||||||
|
c.Redirect(307, redir)
|
||||||
|
} else {
|
||||||
|
c.Redirect(307, defaultRedirect)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that a user is currently logged in.
|
// Ensure that a user is currently logged in.
|
||||||
|
|||||||
@@ -31,13 +31,15 @@ var (
|
|||||||
|
|
||||||
// Wraps the normal configure function, but also gives you access to change the User Function, which is called upon login.
|
// Wraps the normal configure function, but also gives you access to change the User Function, which is called upon login.
|
||||||
// It is used to create or update a user.
|
// It is used to create or update a user.
|
||||||
func ConfigureFull(r *gin.Engine, app_url string, default_redirect string, user_function UserFunc, stubs_on_unconfigured bool) {
|
// The check middleware may be nil, in which case a default is used. Otherwise should be a valid gin middleware, calling c.Next() if okay to proceed.
|
||||||
|
func ConfigureFull(r *gin.Engine, app_url string, default_redirect string, user_function UserFunc, stubs_on_unconfigured bool, check_middleware func(c *gin.Context)) {
|
||||||
userFunc = user_function
|
userFunc = user_function
|
||||||
Configure(r, app_url, default_redirect, stubs_on_unconfigured)
|
Configure(r, app_url, default_redirect, stubs_on_unconfigured, check_middleware)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure and set up the login SDK
|
// Configure and set up the login SDK
|
||||||
func Configure(r *gin.Engine, app_url string, default_redirect string, stubs_on_unconfigured bool) {
|
// The check middleware may be nil, in which case a default is used. Otherwise should be a valid gin middleware, calling c.Next() if okay to proceed.
|
||||||
|
func Configure(r *gin.Engine, app_url string, default_redirect string, stubs_on_unconfigured bool, check_middleware func(c *gin.Context)) {
|
||||||
issuer := os.Getenv("OIDC_ISSUER")
|
issuer := os.Getenv("OIDC_ISSUER")
|
||||||
clientID := os.Getenv("OIDC_CLIENT_ID")
|
clientID := os.Getenv("OIDC_CLIENT_ID")
|
||||||
clientSecret := os.Getenv("OIDC_CLIENT_SECRET")
|
clientSecret := os.Getenv("OIDC_CLIENT_SECRET")
|
||||||
@@ -70,7 +72,12 @@ func Configure(r *gin.Engine, app_url string, default_redirect string, stubs_on_
|
|||||||
|
|
||||||
r.GET("/auth/v2/login", loginHandler)
|
r.GET("/auth/v2/login", loginHandler)
|
||||||
r.GET("/auth/v2/verify", callbackHandler)
|
r.GET("/auth/v2/verify", callbackHandler)
|
||||||
r.GET("/auth/v2/check", EnsureLogin(false), func(ctx *gin.Context) { ctx.JSON(200, gin.H{"success": "true"}) })
|
check_finalizer := func(ctx *gin.Context) { ctx.JSON(200, gin.H{"success": "true"}) }
|
||||||
|
if check_middleware == nil {
|
||||||
|
r.GET("/auth/v2/check", EnsureLogin(false), check_finalizer)
|
||||||
|
} else {
|
||||||
|
r.GET("/auth/v2/check", EnsureLogin(false), check_middleware, check_finalizer)
|
||||||
|
}
|
||||||
r.GET("/auth/v2/logout", logoutHandler)
|
r.GET("/auth/v2/logout", logoutHandler)
|
||||||
|
|
||||||
log.Println("[JHID] Configured successfully")
|
log.Println("[JHID] Configured successfully")
|
||||||
|
|||||||
Reference in new issue
Block a user